---
title: "Expenses and trust analysis"
output: html_notebook
---


#Replication code for 'Misconduct by voters' own representatives does not affect voters' generalized political trust'
#British Journal of Political Science.
#Authors: Edmund Kelly and James Tilley. 
#Corresponding author: Edmund Kelly (email: edmund.kelly@politics.ox.ac.uk).
#June 2024.

#Preparation

```{r Packages}

rm(list = ls()) #Clean your R environment. 

library(foreign)
library(dplyr)
library(lme4)
library(stargazer)
library(sandwich)
library(jtools)
library(cowplot)
library(ggstance)
library(descriptio)
library(sjPlot)
library(GDAtools)
library(sjlabelled)
library(sjmisc)
library(ggplot2)
library(sm)
library(corrplot)
library(r2mlm)
library(sjstats)
library(ggeffects)
library(ggpubr)
library(ordinal)
library(performance)
library(glm.predict)
library(tidyr)
set.seed(1111)
```

```{r Data}
setwd("Your working drive here")
BES <- read.dta("Your file path for the BES Rolling Thunder data here")
EX <- read.csv("Your file path for the MP-level data here")
```

```{r Selecting BES Variables}
BES1 <- data.frame(dplyr::select(BES, turn10, turn05, aaid, apcon201, aaq2, aaq28, 
                          aaq30, aaq32, aaq33, aaq35, 
                          aaq37, aaq43, aaq44, aaq49, 
                          aaq50, aaq57, aaq58, aaq61,
                          aaq73, aaq75, aaq76, aaq78, 
                          aaq79, aaq80, aaq86, aaq87, 
                          aaq88, aaq89, aaq117, w8,
                          aaq118, aaq121, aaq123, 
                          aaq124, aaq125, aaq126, aaq127,
                          aaq128, aaq131, aaq132, 
                          aaq133, aaq136, aaq137, aaq138, 
                          aaq139, aaq140, aaq141, aaq142, 
                          aaq143, aaq145, aaq147, aaq148, 
                          aaq150, aaq151, aaq157, aaq158, aaq159, 
                          aaq171, aaq177, aaq186, 
                          aaq187, aaq188))

BES1 <- BES1 %>% 
  rename(
    constituency = apcon201,
    partid = aaq28, 
    trustprl = aaq57,
    trustplt = aaq58, 
    trustprt = aaq61, 
    approvemp = aaq80, 
    econ12gb = aaq87, 
    votedifference = aaq117, 
    voted05.who = aaq118, 
    soctrust = aaq121, 
    efficacy = aaq123, 
    satdem = aaq128, 
    attention = aaq131, 
    exp.heard = aaq136, 
    most.mp.corrupt = aaq137,
    expense.angry = aaq138, 
    expense.unimportant = aaq139, 
    most.mp.not.corrupt = aaq140, 
    mp.resign.immediate  = aaq141,
    exp.heard.loc = aaq142, 
    exp.amount.loc = aaq143, 
    news = aaq145, 
    news.which = aaq147, 
    age = aaq151, 
    educ.years = aaq157, 
    educbin = aaq158,
    educ = aaq159, 
    occup = aaq171, 
    ethni = aaq177, 
    gender = aaq186, 
  )


```

```{r Merging with Expenses}
BES1$constituency2 <- as.numeric(BES1$constituency)
BES1 <- BES1[,order(colnames(BES1))]

BESX <- merge(BES1, EX, by.x = "constituency2", by.y = "constituencyID")
```

```{r Recoding}

BESX$exp.heard.loc.orig <- BESX$exp.heard.loc
BESX$exp.heard.loc.orig <- na_if(BESX$exp.heard.loc.orig, "don't know")
BESX$exp.amount.loc.orig <- BESX$exp.amount.loc

BESX <- BESX %>% mutate(exp.heard.loc.orig = 
                          recode(exp.heard.loc.orig, 
                                 "yes" = 1, 
                                 "no" = 0))

BESX <- BESX %>% mutate(exp.amount.loc.orig = 
                          recode(exp.amount.loc.orig, 
                                 "0-small amount" = 0,
                                 "1" = 0.1, "2" = 0.2, "3" = 0.3, "4" = 0.4, 
                                 "5" = 0.5, "6" = 0.6, "7" = 0.7, "8" = 0.8, "9" = 0.9,
                                 "10-very large amount" = 1))

BESX <- BESX %>% mutate(approvemp = 
                          recode(approvemp, 
                                 "strongly agree" = 1, 
                                 "agree" = 0.75, 
                                 "neither agree nor disagree" = 0.5,
                                 "disagree" = 0.25,
                                 "strongly disagree" = 0))

BESX <- BESX %>% mutate(most.mp.corrupt = 
                          recode(most.mp.corrupt, 
                                 "strongly agree" = 1,
                                 "agree" = 0.75, 
                                 "neither agree nor disagree" = 0.5, 
                                 "disagree" = 0.25, 
                                 "strongly disagree" = 0))

BESX <- BESX %>% mutate(expense.angry = 
                          recode(expense.angry, 
                                 "strongly agree" = 1,
                                 "agree" = 0.75, 
                                 "neither agree nor disagree" = 0.5, 
                                 "disagree" = 0.25, 
                                 "strongly disagree" = 0))

BESX <- BESX %>% mutate(expense.unimportant = 
                          recode(expense.unimportant, 
                                 "strongly agree" = 1,
                                 "agree" = 0.75, 
                                 "neither agree nor disagree" = 0.5, 
                                 "disagree" = 0.25, 
                                 "strongly disagree" = 0))

BESX <- BESX %>% mutate(most.mp.not.corrupt = 
                          recode(most.mp.not.corrupt, 
                                 "strongly agree" = 1,
                                 "agree" = 0.75, 
                                 "neither agree nor disagree" = 0.5, 
                                 "disagree" = 0.25, 
                                 "strongly disagree" = 0))

BESX <- BESX %>% mutate(mp.resign.immediate = 
                          recode(mp.resign.immediate, 
                                 "strongly agree" = 1,
                                 "agree" = 0.75, 
                                 "neither agree nor disagree" = 0.5, 
                                 "disagree" = 0.25, 
                                 "strongly disagree" = 0))


BESX <- BESX %>% mutate(news = 
                          recode(news, 
                                 "everyday" = 1, 
                                 "sometimes" = 0, 
                                 "not at all" = 0))


BESX <- BESX %>% mutate(trustprl = 
                          recode(trustprl, 
                                 "0-no trust" = 0,
                                 "1" = 0.1, "2" = 0.2, "3" = 0.3, "4" = 0.4, 
                                 "5" = 0.5, "6" = 0.6, "7" = 0.7, "8" = 0.8, "9" = 0.9,
                                 "10-great deal trust" = 1))

BESX <- BESX %>% mutate(trustplt = 
                          recode(trustplt, 
                                 "0-no trust" = 0,
                                 "1" = 0.1, "2" = 0.2, "3" = 0.3, "4" = 0.4, 
                                 "5" = 0.5, "6" = 0.6, "7" = 0.7, "8" = 0.8, "9" = 0.9,
                                 "10-great deal trust" = 1))

BESX <- BESX %>% mutate(trustprt = 
                          recode(trustprt, 
                                 "0-no trust" = 0,
                                 "1" = 0.1, "2" = 0.2, "3" = 0.3, "4" = 0.4, 
                                 "5" = 0.5, "6" = 0.6, "7" = 0.7, "8" = 0.8, "9" = 0.9,
                                 "10-great deal trust" = 1))


BESX <- BESX %>% mutate(approvemp = 
                          recode(approvemp, 
                                 "strongly agree" = 1, 
                                 "agree" = 0.75, 
                                 "neither agree nor disagree" = 0.5,
                                 "disagree" = 0.25,
                                 "strongly disagree" = 0))

BESX <- BESX %>% mutate(soctrust = 
                          recode(soctrust, 
                                 "0-can't trust most" = 0,
                                 "1" = 0.1, "2" = 0.2, "3" = 0.3, "4" = 0.4, 
                                 "5" = 0.5, "6" = 0.6, "7" = 0.7, "8" = 0.8, "9" = 0.9,
                                 "10-can trust most" = 1))

BESX <- BESX %>% mutate(satdem = 
                          recode(satdem, 
                                 "very satisfied" = 1, 
                                 "fairly satisfied" = 0.66, 
                                 "a little dissatisfied" = 0.33, 
                                 "very dissatisfied" = 0))

BESX <- BESX %>% mutate(attention = 
                          recode(attention, 
                                 "0-no attention" = 0,
                                 "1" = 0.1, "2" = 0.2, "3" = 0.3, "4" = 0.4, 
                                 "5" = 0.5, "6" = 0.6, "7" = 0.7, "8" = 0.8, "9" = 0.9,
                                 "10-great deal attention" = 1))

BESX$satdem.binary = ifelse(BESX$satdem >0.5, 1, 0)

BESX <- BESX %>% mutate(exp.heard = 
                          recode(exp.heard, 
                                 "yes" = 1, 
                                 "no" = 0))

BESX <- BESX %>% mutate(exp.heard.loc = 
                          recode(exp.heard.loc, 
                                 "yes" = 1, 
                                 "no" = 0, 
                                 "don't know" = 0))

BESX <- BESX %>% mutate(exp.amount.loc = 
                          recode(exp.amount.loc, 
                                 "0-small amount" = 0,
                                 "1" = 0.1, "2" = 0.2, "3" = 0.3, "4" = 0.4, 
                                 "5" = 0.5, "6" = 0.6, "7" = 0.7, "8" = 0.8, "9" = 0.9,
                                 "10-very large amount" = 1))



BESX <- BESX %>% mutate(educ = 
                          recode(educ, 
                                 "postgraduate degree" = 1,
                                 "university or cnaa first degree, e.g, ba, bsc" = 9/10,
                                 "university or cnaa diploma" = 7/10,
                                 "teaching qualification (not degree)" = 8/10,
                                 "nursing qualification (e.g., sen, src, scm, rgc)" = 7/10,
                                 "higher national certificate (hnc) or higher national diploma" = 6/10,
                                 "gce a level, s level, a2 level, as level, international bacc" = 6/10, 
                                 "scottish higher/higher still grades, scottish slc/supe at hi" = 5/10,
                                 "ordinary national certificate (onc) or diploma (ond), city &" = 5/10,
                                 "gcse a*-c, cse grade 1, gce o level grade a –c, school cer" = 5/10,
                                 "scottish ordinary bands a-c or pass, scottish standard grade" = 4/10,
                                 "gcse grades d-g, cse grades 2-5, gce o level grade d -e, s" = 4/10,
                                 "city & guilds level 2 (craft/intermediate/ordinary) or scotv" = 3/10,
                                 "city & guilds level 1, scotvec national certificate modules," = 3/10,
                                 "clerical and commercial qualification (e.g., typing, shortha" = 3/10,
                                 "recognised trade apprenticeship completed" = 3/10,
                                 "youth training certificate, skill seekers" = 2/10,
                                 "other technical, professional or higher qualification" = 1/10))

BESX$educ[BESX$educbin == "no"] <- 0


BESX <- BESX %>% mutate(econ12gb = 
                          recode(econ12gb, 
                                 "got a lot better" = 1, 
                                 "got a little better" = 1, 
                                 "stayed the same" = 0,
                                 "got a little worse" = 0,
                                 "got a lot worse" = 0))


BESX <- BESX %>% mutate(occup = 
                          recode(occup, 
                                 "professional or higher technical work (work that requires at" = 1,
                                 "manager or senior administrator (e.g. company director, fina" = 1, 
                                 "clerical (e.g. clerk, secretary)" = 5/6, 
                                 "sales or services (e.g. commercial traveller, shop assistant" = 4/6, 
                                 "small business owner (e.g. shop owner, small builder, restau" = 3/6, 
                                 "foreman or supervisor of other workers (e.g. building site f" = 2/6, 
                                 "skilled manual work (e.g. plumber, electrician, fitter, trai" = 1/6, 
                                 "semi-skilled or unskilled manual work (e.g. machine operator" = 0, 
                                 "other" = 3/6))

BESX$age <- as.numeric(BESX$age)
BESX$age <- BESX$age/100


BESX <- BESX %>% mutate(gender = 
                          recode(gender, 
                                 "female" = 1,
                                 "male" = 0))
```

```{r New Variables}
BESX$party <- as.factor(BESX$party)
BESX$party[BESX$party == "Liberal Democrats"] = "Liberal Democrat"

BESX$partymatch = 0
BESX$partymatch[BESX$partid == "conservative"
                & BESX$party == "Conservative Party"] = 1
BESX$partymatch[BESX$partid == "labour"
                & BESX$party == "Labour Party"] = 1
BESX$partymatch[BESX$partid == "liberal democrat"
                & BESX$party == "Liberal Democrat"] = 1
BESX$partymatch[BESX$partid == "plaid cymru"
                & BESX$party == "Plaid Cymru"] = 1
BESX$partymatch[BESX$partid == "scottish national party (snp)"
                & BESX$party == "Scottish National Party"] = 1

BESX$prestige = BESX$frontbench0809 + BESX$Pre.Hon + BESX$Post.Hon
BESX$exp.amount.loc[BESX$exp.heard.loc == 0] = 0
BESX$exp.amount.loc.orig[BESX$exp.heard.loc.orig == 0] = 0
BESX$telegraph = 0
BESX$telegraph[BESX$news.which == "daily telegraph"] = 1
BESX$approvemp.binary = 0
BESX$approvemp.binary[BESX$approvemp > 0.5] = 1
BESX$most.mp.corrupt.binary = 0
BESX$most.mp.corrupt.binary[BESX$most.mp.corrupt>0.5] = 1
BESX$expense.angry.binary = 0
BESX$expense.angry.binary[BESX$expense.angry>0.5] = 1
BESX$most.mp.not.corrupt.binary = 0
BESX$most.mp.not.corrupt.binary[BESX$most.mp.not.corrupt>0.5] = 1
BESX$expense.unimportant.binary = 0
BESX$expense.unimportant.binary[BESX$expense.unimportant>0.5] = 1
BESX$mp.resign.immediate.binary = 0
BESX$mp.resign.immediate.binary[BESX$mp.resign.immediate>0.5] = 1
BESX$Nexis.s.binary = 0
BESX$Nexis.s.binary[BESX$Nexis.s > 0.2809] = 1
```

```{r Rescaling}

BESX$legg = log(1 + BESX$legg)

BESX$totexp_excludehome = log(1 + BESX$totexp_excludehome)

BESX$secondhometot = log(1 + BESX$secondhometot)

BESX$redistrict_change = BESX$redistrict_change/100

BESX$se_managerial = BESX$se_managerial/100

BESX$ukp54margin_notional = BESX$ukp54margin_notional/100

BESX$unemployed = BESX$unemployed/100

BESX$density = BESX$density/100

BESX$distancelivedfromLondon = BESX$distancelivedfromLondon/100

BESX$age.x = BESX$age.x/100

BESX$tenure = BESX$tenure/100

BESX$prescandal.article.count = BESX$prescandal.article.count/100
```

```{r Rescaling 2}
BESX = BESX %>% 
  
  filter(constituency2 != "573", 
         constituency2 != "586")

BESX$Nexis.s <- as.numeric(scale(BESX$Nexis.s))
BESX$secondhometot <- as.numeric(scale(BESX$secondhometot))
BESX$totexp_excludehome <- as.numeric(scale(BESX$totexp_excludehome))
BESX$legg <- as.numeric(scale(BESX$legg))
```

```{r People are angry}

BESX_angry = BESX %>% 
  
  select(w8, expense.angry, expense.unimportant) %>% 
  
  na.omit()

descriptio::weighted.table(BESX_angry$expense.angry, w = BESX_angry$w8)

(7937.6+4806.0)/(7937.6+4806.0+882.3+371.8+140.6)

descriptio::weighted.table(BESX_angry$expense.unimportant, w = BESX_angry$w8)

(781.1+182.8)/(781.1+182.8+837.5+4543.3+7793.5)

```

#Main paper

```{r Table D1: Attributions}

BESX_t1 = BESX %>% 
  
  select(Nexis.s, legg, secondhometot, totexp_excludehome, incumbentstand.original, inner_london, distancelivedfromLondon, female, unemployed, se_managerial, density, redistrict_change, ukp54margin_notional, prestige, age, educ, attention, news, telegraph, occup, soctrust, econ12gb, exp.heard.loc, exp.amount.loc, constituency2, partymatch) %>% 
  
  na.omit()

t1_1 <- glmer(formula = exp.heard.loc ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
             + (1|constituency2), 
             family = binomial(link = "logit"),  data = BESX_t1, 
             nAGQ = 0, na.action = na.omit)

t1_2 <- glmer(formula = exp.heard.loc ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), family = binomial(link = "logit"),
              data = BESX_t1, nAGQ = 0, na.action = na.omit)

t1_3 <- glmer(formula = exp.heard.loc ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome +  partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige +
                 age + educ + attention + 
                 news + telegraph + 
                 occup + soctrust + econ12gb  + 
                 (1|constituency2), family = binomial(link = "logit"),
              data = BESX_t1, nAGQ = 0, na.action = na.omit)

t1_4 <- lmer(formula = exp.amount.loc ~ Nexis.s + legg + 
                secondhometot + totexp_excludehome + 
                + (1|constituency2),  data = BESX_t1, 
               na.action = na.omit)

t1_5 <- lmer(formula = exp.amount.loc ~ Nexis.s + legg + 
                secondhometot + totexp_excludehome + 
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                (1|constituency2), 
              data = BESX_t1, na.action = na.omit)

t1_6 <- lmer(formula = exp.amount.loc ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome +  partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige + 
                age + educ + attention + 
                news + telegraph + 
                occup + soctrust + econ12gb  + 
                (1|constituency2), 
              data = BESX_t1, na.action = na.omit)

#R squared

r2(t1_1)
r2(t1_2)
r2(t1_3)
r2(t1_4)
r2(t1_5)
r2(t1_6)

#Table

stargazer(t1_4, t1_5, t1_6, t1_1, t1_2, t1_3, type = "text",
          star.char = c("*", "**"), 
          star.cutoffs = c(0.05, 0.01), 
          out = "Table1.html")

#Prediction for Ann Widdecombe.
ggpredict(t1_6, terms = c("Nexis.s[0.1108043]"))

#Prediction for Sir Peter Viggers. 
ggpredict(t1_6, terms = c("Nexis.s[2.95326462]"))

```

```{r Figure 1: Attributions}

figure_1 <- plot_models(t1_4, t1_5, t1_6,
                        dot.size = 1.5,
            axis.labels = c("Other Claims", "Second Home Claims", "Legg Repayments", "Media Implication"), 
            m.labels = c("No Controls", "MP Controls", "All Controls"), 
            legend.title = "Model:", wrap.title = c(80), 
            colors = "gs", 
            rm.terms = c("partymatch", "incumbentstand.original", "inner_london", "distancelivedfromLondon",  
                 "female", "unemployed", "se_managerial", "density", "redistrict_change", "ukp54margin_notional", "prestige", "prescandal.article.count", "occupnever worked", "occupother", "occupsemi-skilled or unskilled manual work (e.g. machine operator", "occupskilled manual work (e.g. plumber, electrician, fitter, trai", "occupforeman or supervisor of other workers (e.g. building site f", "occupsmall business owner (e.g. shop owner, small builder, restau", "occupsales or services (e.g. commercial traveller, shop assistant", "occupclerical (e.g. clerk, secretary)", "occupmanager or senior administrator (e.g. company director, fina", "educuniversity or cnaa first degree, e.g, ba, bsc", "educother technical, professional or higher qualification", "educyouth training certificate, skill seekers", "educrecognised trade apprenticeship completed", "educclerical and commercial qualification (e.g., typing, shortha", "educcity & guilds level 1, scotvec national certificate modules,", "educcity & guilds level 2 (craft/intermediate/ordinary) or scotv", "educgcse grades d-g, cse grades 2-5, gce o level grade d –e, s", "educscottish ordinary bands a-c or pass, scottish standard grade", "educgcse a*-c, cse grade 1, gce o level grade a –c, school cer", "educordinary national certificate (onc) or diploma (ond), city &",
                 "educuniversity or cnaa diploma", "educteaching qualification (not degree)", "educnursing qualification (e.g., sen, src, scm, rgc)", "educhigher national certificate (hnc) or higher national diploma", "educgce a level, s level, a2 level, as level, international bacc", "educscottish higher/higher still grades, scottish slc/supe at hi", "educordinary national certificate (onc) or diploma (ond), city", 
                 "age", "educ", "attention", "news", "telegraph", "occup", "soctrust", "econ12gb")) + 
  ylim(-0.1, 0.1) + 
  geom_hline(yintercept = 0, linetype = "dashed") +
  theme_minimal() +
  theme(text = element_text(size = 12, family = "serif"), 
        plot.title = element_text(hjust = 0.5), 
        plot.caption = element_text(hjust = 0.5)) +
  labs(y = "Standardised Estimates") + 
  theme(aspect.ratio=1/2) + 
  theme(plot.margin=grid::unit(c(0,0,0,0), "mm"))

figure_1

ggsave("Figure1.png", plot = figure_1, dpi = 600)

ggsave("Figure1.pdf", plot = figure_1)


```

```{r Table D2: Eroding}

BESX_t2 = BESX %>% 
  
  select(Nexis.s, legg, secondhometot, totexp_excludehome, incumbentstand.original, inner_london, distancelivedfromLondon, female, unemployed, se_managerial, density, redistrict_change, ukp54margin_notional, prestige, age, educ, attention, news, telegraph, occup, soctrust, econ12gb, approvemp, constituency2, partymatch) %>% 
  
  na.omit() 

t2_4 <- lmer(formula = approvemp ~ Nexis.s + legg 
              + secondhometot + totexp_excludehome
              + (1|constituency2), 
              data = BESX_t2, 
              na.action = na.omit)

t2_5 <- lmer(formula = approvemp ~ Nexis.s + legg + 
                secondhometot + totexp_excludehome +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige +
                (1|constituency2), 
              data = BESX_t2, na.action = na.omit)

t2_6 <- lmer(formula = approvemp ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t2, na.action = na.omit)

BESX_t2$approvemp<-as.factor(BESX_t2$approvemp)

t2_1 <- clmm(formula = approvemp ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), link = "logit",
               data = BESX_t2, nAGQ = 1,
               na.action = na.omit)

t2_2 <- clmm(formula = approvemp ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige +
                 (1|constituency2), nAGQ = 0, link = "logit",
               data = BESX_t2, na.action = na.omit)

t2_3 <- clmm(formula = approvemp ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige +
                age + educ + attention + 
                news + telegraph + 
                occup + soctrust + econ12gb  +
                 (1|constituency2), nAGQ = 0, link = "logit",
               data = BESX_t2, na.action = na.omit)

#R squared

r2(t2_1)
r2(t2_2)
r2(t2_3)
r2(t2_4)
r2(t2_5)
r2(t2_6)

#Table for the linear models (Tables created manually for the logit models due to incompatibility with the Stargazer package). 

stargazer(t2_4, t2_5, t2_6, type = "text",
          
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          title = "Table 2", 
          out = "Table2.html")

#Predicted scores when moving from the least to the most implicated MP. 
ggpredict(t2_6, terms = c("Nexis.s[-1.633]"))
ggpredict(t2_6, terms = c("Nexis.s[3.659]"))

```

```{r Figure 2: Eroding}
figure_2 <- plot_models(t2_4, t2_5, t2_6, 
                        dot.size = 1.5,
            axis.labels = c("Other Claims", "Second Home Claims", "Legg Repayments", "Media Implication"), 
            m.labels = c("No Controls", "MP Controls", "All Controls"), 
            legend.title = "Model:", wrap.title = c(80), 
            colors = "gs", 
            rm.terms = c("partymatch", "incumbentstand.original", "inner_london", "distancelivedfromLondon",  
                 "female", "unemployed", "se_managerial", "density", "redistrict_change", "ukp54margin_notional", "prestige", "prescandal.article.count", "occupnever worked", "occupother", "occupsemi-skilled or unskilled manual work (e.g. machine operator", "occupskilled manual work (e.g. plumber, electrician, fitter, trai", "occupforeman or supervisor of other workers (e.g. building site f", "occupsmall business owner (e.g. shop owner, small builder, restau", "occupsales or services (e.g. commercial traveller, shop assistant", "occupclerical (e.g. clerk, secretary)", "occupmanager or senior administrator (e.g. company director, fina", "educuniversity or cnaa first degree, e.g, ba, bsc", "educother technical, professional or higher qualification", "educyouth training certificate, skill seekers", "educrecognised trade apprenticeship completed", "educclerical and commercial qualification (e.g., typing, shortha", "educcity & guilds level 1, scotvec national certificate modules,", "educcity & guilds level 2 (craft/intermediate/ordinary) or scotv", "educgcse grades d-g, cse grades 2-5, gce o level grade d –e, s", "educscottish ordinary bands a-c or pass, scottish standard grade", "educgcse a*-c, cse grade 1, gce o level grade a –c, school cer", "educordinary national certificate (onc) or diploma (ond), city &",
                 "educuniversity or cnaa diploma", "educteaching qualification (not degree)", "educnursing qualification (e.g., sen, src, scm, rgc)", "educhigher national certificate (hnc) or higher national diploma", "educgce a level, s level, a2 level, as level, international bacc", "educscottish higher/higher still grades, scottish slc/supe at hi", "educordinary national certificate (onc) or diploma (ond), city", 
                 "age", "educ", "attention", "news", "telegraph", "occup", "soctrust", "econ12gb")) + 
  ylim(-0.05, 0.05) + 
  geom_hline(yintercept = 0, linetype = "dashed") +
  theme_minimal() +
  theme(text = element_text(size = 12, family = "serif"), 
        plot.title = element_text(hjust = 0.5), 
        plot.caption = element_text(hjust = 0.5)) +
  labs(y = "Standardised Estimates") +
  theme(aspect.ratio=1/2) + 
  theme(plot.margin=grid::unit(c(0,0,0,0), "mm"))

figure_2

ggsave("Figure2.pdf", plot = figure_2)
```

```{r Table D3: Spillovers}

BESX_t3a = BESX %>% 
  
  select(Nexis.s, legg, secondhometot, totexp_excludehome, incumbentstand.original, inner_london, distancelivedfromLondon, female, unemployed, se_managerial, density, redistrict_change, ukp54margin_notional, prestige, age, educ, attention, news, telegraph, occup, soctrust, econ12gb, trustplt, constituency2, partymatch) %>% 
  
  na.omit() 

#-----1 -  Trust in politicians-----

t3_1 <- lmer(formula = trustplt ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = BESX_t3a, 
               na.action = na.omit)

t3_2 <- lmer(formula = trustplt ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3a, na.action = na.omit)

t3_3 <- lmer(formula = trustplt ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t3a, na.action = na.omit)

#-----2 -  Trust in parliament-----

BESX_t3b = BESX %>% 
  
  select(Nexis.s, legg, secondhometot, totexp_excludehome, incumbentstand.original, inner_london, distancelivedfromLondon, female, unemployed, se_managerial, density, redistrict_change, ukp54margin_notional, prestige, age, educ, attention, news, telegraph, occup, soctrust, econ12gb, trustprl, constituency2, partymatch) %>% 
  
  na.omit() 

t3_4 <- lmer(formula = trustprl ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = BESX_t3b, 
               na.action = na.omit)

t3_5 <- lmer(formula = trustprl ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3b, na.action = na.omit)

t3_6 <- lmer(formula = trustprl ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +

                 (1|constituency2), 
               data = BESX_t3b, na.action = na.omit)

#-----3 -  Satisfaction-----

BESX_t3c = BESX %>% 
  
  select(Nexis.s, legg, secondhometot, totexp_excludehome, incumbentstand.original, inner_london, distancelivedfromLondon, female, unemployed, se_managerial, density, redistrict_change, ukp54margin_notional, prestige, age, educ, attention, news, telegraph, occup, soctrust, econ12gb, satdem, constituency2, partymatch) %>% 
  
  na.omit() 

t3_7 <- lmer(formula = satdem ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = BESX_t3c, 
               na.action = na.omit)

t3_8 <- lmer(formula = satdem ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3c, na.action = na.omit)

t3_9 <- lmer(formula = satdem ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +

                 (1|constituency2), 
               data = BESX_t3c, na.action = na.omit)
#-----4 -  Spillover Perceptions-----

BESX_t3d = BESX %>% 
  
  select(Nexis.s, legg, secondhometot, totexp_excludehome, incumbentstand.original, inner_london, distancelivedfromLondon, female, unemployed, se_managerial, density, redistrict_change, ukp54margin_notional, prestige, age, educ, attention, news, telegraph, occup, soctrust, econ12gb, most.mp.corrupt, constituency2, partymatch, prescandal.article.count) %>% 
  
  na.omit() 

BESX_t3d$most.mp.corrupt = as.numeric(BESX_t3d$most.mp.corrupt
                                    )

t3_10 <- lmer(formula = most.mp.corrupt ~ Nexis.s + legg 
            + secondhometot + totexp_excludehome
            + (1|constituency2), 
            data = BESX_t3d, 
            na.action = na.omit)

t3_11 <- lmer(formula = most.mp.corrupt ~ Nexis.s + legg + 
              secondhometot + totexp_excludehome +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige +
              (1|constituency2), 
            data = BESX_t3d, na.action = na.omit)

t3_12 <- lmer(formula = most.mp.corrupt ~   
              Nexis.s + 
              legg + 
              secondhometot + totexp_excludehome + partymatch +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige +
              age + educ + attention + 
              news + telegraph + 
              occup + soctrust + econ12gb +

              (1|constituency2), 
            data = BESX_t3d, na.action = na.omit)
#-----5 -  Tables: Spillovers: -----

r2(t3_1)
r2(t3_2)
r2(t3_3)
r2(t3_4)
r2(t3_5)
r2(t3_6)
r2(t3_7)
r2(t3_8)
r2(t3_9)
r2(t3_10)
r2(t3_11)
r2mlm(t3_12)

stargazer(t3_1, t3_2, t3_3, type = "text",
          t3_4, t3_5, t3_6, 
          t3_7, t3_8, t3_9, 
          t3_10, t3_11, t3_12, 
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01),
          out = "Table3.html")
```

```{r Figure 3: Spillovers}
figure_3a <- plot_models(t3_3, dot.size = 1.5, spacing = 0.6,
            axis.labels = c("Other Claims", "Second Home Claims", "Legg Repayments", "Media Implication"), 
            legend.title = "Model:", wrap.title = c(80), 
            colors = "gs",
            rm.terms = c("partymatch", "incumbentstand.original", "inner_london", "distancelivedfromLondon",  
                 "female", "unemployed", "se_managerial", "density", "redistrict_change", "ukp54margin_notional", "prestige", "prescandal.article.count", "occupnever worked", "occupother", "occupsemi-skilled or unskilled manual work (e.g. machine operator", "occupskilled manual work (e.g. plumber, electrician, fitter, trai", "occupforeman or supervisor of other workers (e.g. building site f", "occupsmall business owner (e.g. shop owner, small builder, restau", "occupsales or services (e.g. commercial traveller, shop assistant", "occupclerical (e.g. clerk, secretary)", "occupmanager or senior administrator (e.g. company director, fina", "educuniversity or cnaa first degree, e.g, ba, bsc", "educother technical, professional or higher qualification", "educyouth training certificate, skill seekers", "educrecognised trade apprenticeship completed", "educclerical and commercial qualification (e.g., typing, shortha", "educcity & guilds level 1, scotvec national certificate modules,", "educcity & guilds level 2 (craft/intermediate/ordinary) or scotv", "educgcse grades d-g, cse grades 2-5, gce o level grade d –e, s", "educscottish ordinary bands a-c or pass, scottish standard grade", "educgcse a*-c, cse grade 1, gce o level grade a –c, school cer", "educordinary national certificate (onc) or diploma (ond), city &",
                 "educuniversity or cnaa diploma", "educteaching qualification (not degree)", "educnursing qualification (e.g., sen, src, scm, rgc)", "educhigher national certificate (hnc) or higher national diploma", "educgce a level, s level, a2 level, as level, international bacc", "educscottish higher/higher still grades, scottish slc/supe at hi", "educordinary national certificate (onc) or diploma (ond), city", 
                 "age", "educ", "attention", "news", "telegraph", "occup", "soctrust", "econ12gb")) + 
  ylim(-0.05, 0.05) + 
  geom_hline(yintercept = 0, linetype = "dashed") +
  theme_minimal() +
  theme(text = element_text(size = 8, family = "serif"), 
        plot.title = element_text(hjust = 0.5), 
        plot.caption = element_text(hjust = 0.5)) + 
  labs(y = NULL, title = "Trust in Politicians") +
  theme(legend.position = "none")+
  theme(plot.margin=grid::unit(c(0,0,0,0), "mm"))

figure_3b <- plot_models(t3_6, dot.size = 1.5, spacing = 0.6,
            axis.labels = c("Other Claims", "Second Home Claims", "Legg Repayments", "Media Implication"), 
            legend.title = "Model:", wrap.title = c(80), 
            colors = "gs",
            rm.terms = c("partymatch", "incumbentstand.original", "inner_london", "distancelivedfromLondon",  
                 "female", "unemployed", "se_managerial", "density", "redistrict_change", "ukp54margin_notional", "prestige", "prescandal.article.count", "occupnever worked", "occupother", "occupsemi-skilled or unskilled manual work (e.g. machine operator", "occupskilled manual work (e.g. plumber, electrician, fitter, trai", "occupforeman or supervisor of other workers (e.g. building site f", "occupsmall business owner (e.g. shop owner, small builder, restau", "occupsales or services (e.g. commercial traveller, shop assistant", "occupclerical (e.g. clerk, secretary)", "occupmanager or senior administrator (e.g. company director, fina", "educuniversity or cnaa first degree, e.g, ba, bsc", "educother technical, professional or higher qualification", "educyouth training certificate, skill seekers", "educrecognised trade apprenticeship completed", "educclerical and commercial qualification (e.g., typing, shortha", "educcity & guilds level 1, scotvec national certificate modules,", "educcity & guilds level 2 (craft/intermediate/ordinary) or scotv", "educgcse grades d-g, cse grades 2-5, gce o level grade d –e, s", "educscottish ordinary bands a-c or pass, scottish standard grade", "educgcse a*-c, cse grade 1, gce o level grade a –c, school cer", "educordinary national certificate (onc) or diploma (ond), city &",
                 "educuniversity or cnaa diploma", "educteaching qualification (not degree)", "educnursing qualification (e.g., sen, src, scm, rgc)", "educhigher national certificate (hnc) or higher national diploma", "educgce a level, s level, a2 level, as level, international bacc", "educscottish higher/higher still grades, scottish slc/supe at hi", "educordinary national certificate (onc) or diploma (ond), city", 
                 "age", "educ", "attention", "news", "telegraph", "occup", "soctrust", "econ12gb")) + 
  ylim(-0.05, 0.05) + 
  geom_hline(yintercept = 0, linetype = "dashed") +
  theme_minimal() +
  theme(text = element_text(size = 8, family = "serif"), 
        plot.title = element_text(hjust = 0.5), 
        plot.caption = element_text(hjust = 0.5)) + 
  labs(y = NULL, title = "Trust in Parliament")+
  theme(axis.text.y = element_blank()) + 
  theme(legend.position = "none")+
  theme(plot.margin=grid::unit(c(0,0,0,0), "mm"))

figure_3c <- plot_models(t3_9, dot.size = 1.5, spacing = 0.6,
            axis.labels = c("Other Claims", "Second Home Claims", "Legg Repayments", "Media Implication"),
            legend.title = "Model:", wrap.title = c(80), 
            colors = "gs",
            rm.terms = c("partymatch", "incumbentstand.original", "inner_london", "distancelivedfromLondon",  
                 "female", "unemployed", "se_managerial", "density", "redistrict_change", "ukp54margin_notional", "prestige", "prescandal.article.count", "occupnever worked", "occupother", "occupsemi-skilled or unskilled manual work (e.g. machine operator", "occupskilled manual work (e.g. plumber, electrician, fitter, trai", "occupforeman or supervisor of other workers (e.g. building site f", "occupsmall business owner (e.g. shop owner, small builder, restau", "occupsales or services (e.g. commercial traveller, shop assistant", "occupclerical (e.g. clerk, secretary)", "occupmanager or senior administrator (e.g. company director, fina", "educuniversity or cnaa first degree, e.g, ba, bsc", "educother technical, professional or higher qualification", "educyouth training certificate, skill seekers", "educrecognised trade apprenticeship completed", "educclerical and commercial qualification (e.g., typing, shortha", "educcity & guilds level 1, scotvec national certificate modules,", "educcity & guilds level 2 (craft/intermediate/ordinary) or scotv", "educgcse grades d-g, cse grades 2-5, gce o level grade d –e, s", "educscottish ordinary bands a-c or pass, scottish standard grade", "educgcse a*-c, cse grade 1, gce o level grade a –c, school cer", "educordinary national certificate (onc) or diploma (ond), city &",
                 "educuniversity or cnaa diploma", "educteaching qualification (not degree)", "educnursing qualification (e.g., sen, src, scm, rgc)", "educhigher national certificate (hnc) or higher national diploma", "educgce a level, s level, a2 level, as level, international bacc", "educscottish higher/higher still grades, scottish slc/supe at hi", "educordinary national certificate (onc) or diploma (ond), city", 
                 "age", "educ", "attention", "news", "telegraph", "occup", "soctrust", "econ12gb")) + 
  ylim(-0.05, 0.05) + 
  geom_hline(yintercept = 0, linetype = "dashed") +
  theme_minimal() +
  theme(text = element_text(size = 8, family = "serif"), 
        plot.title = element_text(hjust = 0.5), 
        plot.caption = element_text(hjust = 0.5)) + 
  labs(x = NULL,  y = "Standardised estimates", title = "Satisfaction with Democracy")+
  theme(legend.position = "none")+
  theme(plot.margin=grid::unit(c(1,0,0,0), "mm"))

figure_3d <- plot_models(t3_12, dot.size = 1.5, spacing = 0.6, 
            axis.labels = c("Other Claims", "Second Home Claims", "Legg Repayments", "Media Implication"), 
            legend.title = "Model:", wrap.title = c(80), 
            colors = "gs",
            rm.terms = c("partymatch", "incumbentstand.original", "inner_london", "distancelivedfromLondon",  
                 "female", "unemployed", "se_managerial", "density", "redistrict_change", "ukp54margin_notional", "prestige", "prescandal.article.count", "occupnever worked", "occupother", "occupsemi-skilled or unskilled manual work (e.g. machine operator", "occupskilled manual work (e.g. plumber, electrician, fitter, trai", "occupforeman or supervisor of other workers (e.g. building site f", "occupsmall business owner (e.g. shop owner, small builder, restau", "occupsales or services (e.g. commercial traveller, shop assistant", "occupclerical (e.g. clerk, secretary)", "occupmanager or senior administrator (e.g. company director, fina", "educuniversity or cnaa first degree, e.g, ba, bsc", "educother technical, professional or higher qualification", "educyouth training certificate, skill seekers", "educrecognised trade apprenticeship completed", "educclerical and commercial qualification (e.g., typing, shortha", "educcity & guilds level 1, scotvec national certificate modules,", "educcity & guilds level 2 (craft/intermediate/ordinary) or scotv", "educgcse grades d-g, cse grades 2-5, gce o level grade d –e, s", "educscottish ordinary bands a-c or pass, scottish standard grade", "educgcse a*-c, cse grade 1, gce o level grade a –c, school cer", "educordinary national certificate (onc) or diploma (ond), city &",
                 "educuniversity or cnaa diploma", "educteaching qualification (not degree)", "educnursing qualification (e.g., sen, src, scm, rgc)", "educhigher national certificate (hnc) or higher national diploma", "educgce a level, s level, a2 level, as level, international bacc", "educscottish higher/higher still grades, scottish slc/supe at hi", "educordinary national certificate (onc) or diploma (ond), city", 
                 "age", "educ", "attention", "news", "telegraph", "occup", "soctrust", "econ12gb")) + 
  ylim(-0.05, 0.05) + 
  geom_hline(yintercept = 0, linetype = "dashed") +
  theme_minimal() +
  theme(text = element_text(size = 8, family = "serif"), 
        plot.title = element_text(hjust = 0.5), 
        plot.caption = element_text(hjust = 0.5)) + 
  labs(x = NULL, y = "Standardised estimates", title = "Spillover Perceptions")+
  theme(axis.text.y = element_blank()) + 
  theme(legend.position = "none")+
  theme(plot.margin=grid::unit(c(1,0,0,0), "mm"))

figure_3 <- ggarrange(figure_3a, figure_3b, figure_3c, figure_3d, nrow = 2, ncol = 2,
          align = "hv") 
figure_3

ggsave("Figure3.pdf", figure_3, width = 15, height = 10, units = "cm")
ggsave("Figure3a.pdf", figure_3a, width = 15, height = 10, units = "cm")

```

```{r Figure 4 Preparation}

#Note: run the Endogenous controls section first to make sure the correct data is loaded. 

BEStrace <- data.frame(select(BESLP, 
                              satdem05pre, satdem05cam, satdem05post, 
                              satdem06, satdem08, satdem09, satdem10pre, 
                              satdem10cam, satdem10post, Nexis.s09,  
                              exploc10))

BEStrace = BEStrace %>% 
  rename("06/2006" = satdem06, 
         "06/2008" = satdem08, 
         "06/2009" = satdem09, 
         "01/2010" = satdem10pre, 
         "05/2010" = satdem10cam, 
         "09/2010" = satdem10post, 
         "01/2005" = satdem05pre, 
         "05/2005" = satdem05cam, 
         "09/2005" = satdem05post)

BEStrace$EXPLOC_BINARY = BEStrace$exploc10
BEStrace$EXPLOC_BINARY[is.na(BEStrace$exploc10) == T] = 0 

BEStrace = BEStrace %>% 
  pivot_longer(cols = c("01/2005", "05/2005", "09/2005", "06/2006", "06/2008", "06/2009", "01/2010", "05/2010", "09/2010"), 
               names_to = "YEAR", values_to = "SATDEM") %>% 
  
  mutate(ORDER = case_when(YEAR == "01/2005" ~  1, 
                           YEAR == "05/2005" ~ 2, 
                           YEAR == "09/2005" ~ 3, 
                           YEAR == "06/2006" ~ 4, 
                           YEAR == "06/2008" ~ 5, 
                           YEAR == "06/2009" ~ 6, 
                           YEAR == "01/2010" ~ 7, 
                           YEAR == "05/2010" ~ 8, 
                           YEAR == "09/2010" ~ 9)) %>% 
  
  mutate(EXPLOC_BINARY = as.factor(EXPLOC_BINARY)) %>% 
  
  mutate(EXPLOC_BINARY = case_when(EXPLOC_BINARY == "1" ~ "MP implicated", 
                                   EXPLOC_BINARY == "0" ~ "MP not implicated"))

library(gmodels)

```

```{r Figure 4: Dynamics of Trust}

custom_colors <- c("MP implicated" = "black", "MP not implicated" = "grey")

BEStrace_summary = BEStrace %>% 
    group_by(ORDER, EXPLOC_BINARY) %>% 
      summarise(SATDEM_MEAN = ci(SATDEM, na.rm = T)[1], 
                      SATDEM_LO = ci(SATDEM, na.rm = T)[2],
                      SATDEM_HI = ci(SATDEM, na.rm = T)[3]) %>% 
  mutate(NEWORDER = ifelse(EXPLOC_BINARY == "MP not implicated", ORDER + 0.05, ORDER))

figure_4 = BEStrace_summary %>% 
    ggplot(
    aes(x = NEWORDER, y = SATDEM_MEAN, ymin = SATDEM_LO, ymax = SATDEM_HI, color = EXPLOC_BINARY, group = EXPLOC_BINARY)
  ) + 
  geom_point(size = 2.5) +
  geom_linerange(aes(ymin = SATDEM_LO, ymax = SATDEM_HI), linewidth = 0.85) +
  geom_path(linewidth = 0.5, linetype = "dashed") + 
  annotate("segment", x = 5.5, xend = 5.5, y = -Inf, yend = 0.455, color = "black", linetype = "solid") +
  scale_color_manual(values = custom_colors) +
  labs(color = "MP status") +
  theme_minimal() + 
  theme(panel.background = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), 
        axis.line = element_line(colour = "black"))+
  scale_x_continuous(name = "Wave", breaks = c(1, 2, 3, 4, 5, 6, 7, 8, 9), labels = c("2005 Pre-Campaign", "2005 Campaign", "2005 Post-Election", 
                                               "2006", "2008", "2009", "2010 Pre-Campaign", 
                                               "2010 Campaign", "2010 Post-Election")) + 
  scale_y_continuous(name = "Satisfaction with democracy", limits = c(0.3, 0.5)) + 
  theme(text=element_text(family="serif"), axis.title = element_text(size = 16), 
        axis.text.y = element_text(size = 16), axis.text.x = element_text(size = 9
                                                                      ))  + 
  theme(aspect.ratio=1/4) + 
  theme(plot.margin=grid::unit(c(0,0,0,1), "mm")) +
  annotate("text", x = 5.5, y = 0.465, label = "Expenses scandal", family = "serif", size = 6.5) 
  

figure_4

ggsave("Figure4.pdf", plot = figure_4, height = 13, width = 30, units = "cm")
ggsave("Figure4.png", plot = figure_4, height = 15, width = 30, units = "cm")


```

#Appendices

```{r Table C1: Summary Statistics, echo = FALSE}

appendix1 <- BESX %>% dplyr::select(exp.heard.loc, exp.amount.loc, approvemp, trustplt, trustprl, satdem, most.mp.corrupt, 
                             Nexis.s, legg, secondhometot, totexp_excludehome, 
                             partymatch, incumbentstand.original, inner_london, distancelivedfromLondon, female, unemployed, se_managerial, density,                                              redistrict_change, ukp54margin_notional, prestige, prescandal.article.count, 
                             age, educ, attention, news, telegraph, occup, soctrust, econ12gb)

appendixtable1 <- stargazer(appendix1, median = TRUE, iqr = TRUE, out = "Appendix1.html", type = "text")

```

```{r Table C2: Correlations}
corr_data = EX %>% 
  select(Nexis.s, Nexis.s09, legg, secondhometot, totexp_excludehome, curtice, curtice.ours, scandal.article.count)

corr_map <- cor(corr_data, use = "pairwise.complete.obs")
stargazer(corr_map, type = "text")

```

```{r Appendix E: Attribution and Co-Partisanship}

ap2.1 <- lmer(formula = exp.amount.loc ~ Nexis.s + legg + 
                secondhometot + totexp_excludehome + 
                partymatch + Nexis.s*partymatch + legg*partymatch + secondhometot*partymatch 
                + (1|constituency2), data = BESX_t1, 
               na.action = na.omit)

ap2.2 <- lmer(formula = exp.amount.loc ~ Nexis.s + legg + 
                secondhometot + totexp_excludehome + 
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                Nexis.s*partymatch + legg*partymatch + secondhometot*partymatch +
                (1|constituency2),
              data = BESX_t1, na.action = na.omit)

ap2.3 <- lmer(formula = exp.amount.loc ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome +  partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige +
                age + educ + attention + 
                news + telegraph + 
                occup + soctrust + econ12gb  + 
                Nexis.s*partymatch + legg*partymatch + secondhometot*partymatch +
                (1|constituency2), 
              data = BESX_t1, na.action = na.omit)

stargazer(ap2.1, ap2.2, ap2.3, type = "text",
          
          star.char = c("*", "**"), 
          star.cutoffs = c(0.05, 0.01), 
          dep.var.caption = c("Multilevel Linear"),
          dep.var.labels = c("Perceived Implication"),
          title = "Appendix 2", 
          out = "Appendix2.html")
```

```{r Appendix E: Eroding and Co-Partisanship}

#Note: now check if approvemp is on 0-1 scale, if not then amend this. 

BESX_t2$approvemp = (as.numeric(BESX_t2$approvemp)-1)/4

ap3.1 <- lmer(formula = approvemp ~ Nexis.s + legg + 
                secondhometot + totexp_excludehome + 
                partymatch + Nexis.s*partymatch + legg*partymatch + secondhometot*partymatch 
                + (1|constituency2), data = BESX_t2, 
               na.action = na.omit)

ap3.2 <- lmer(formula = approvemp ~ Nexis.s + legg + 
                secondhometot + totexp_excludehome + 
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige + 
                Nexis.s*partymatch + legg*partymatch + secondhometot*partymatch +
                (1|constituency2),
              data = BESX_t2, na.action = na.omit)

ap3.3 <- lmer(formula = approvemp ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome +  partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige + 
                age + educ + attention + 
                news + telegraph + 
                occup + soctrust + econ12gb  + 
                Nexis.s*partymatch + legg*partymatch + secondhometot*partymatch +
                (1|constituency2), 
              data = BESX_t2, na.action = na.omit)

stargazer(ap3.1, ap3.2, ap3.3, type = "text",
          
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          dep.var.caption = c("Multilevel Linear"),
          dep.var.labels = c("Specific Support"),
          title = "Appendix 4", 
          out = "Appendix4.html")
```

```{r Appendix E: Diffuse Trust and Co-Partisanship}

#-----1 -  Models: Politicians-----
a5_1 <- lmer(formula = trustplt ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = subset(BESX_t3a, partymatch == 1), 
               na.action = na.omit)

a5_2 <- lmer(formula = trustplt ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|constituency2), 
               data = subset(BESX_t3a, partymatch == 1), na.action = na.omit)

a5_3 <- lmer(formula = trustplt ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome + partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige + 
                 age + educ + attention +
                 news + telegraph + 
                 occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = subset(BESX_t3a, partymatch == 1), na.action = na.omit)

#-----2 -  Models: Parliament-----
a5_4 <- lmer(formula = trustprl ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = subset(BESX_t3b, partymatch == 1), 
               na.action = na.omit)

a5_5 <- lmer(formula = trustprl ~  Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                  female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|constituency2), 
               data = subset(BESX_t3b, partymatch == 1), na.action = na.omit)

a5_6 <- lmer(formula = trustprl ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige + 
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = subset(BESX_t3b, partymatch == 1), na.action = na.omit)
#-----3 -  Models: Satisfaction-----

a5_7 <- lmer(formula = satdem ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = subset(BESX_t3c, partymatch == 1), 
               na.action = na.omit)

a5_8 <- lmer(formula = satdem ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|constituency2), 
               data = subset(BESX_t3c, partymatch == 1), na.action = na.omit)

a5_9 <- lmer(formula = satdem ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige + 
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = subset(BESX_t3c, partymatch == 1), na.action = na.omit)

#-----4 -  Models: Spillover Perceptions-----
a5_10 <- lmer(formula = most.mp.corrupt ~ Nexis.s + legg 
            + secondhometot + totexp_excludehome
            + (1|constituency2), 
            data = subset(BESX_t3d, partymatch == 1), 
            na.action = na.omit)

a5_11 <- lmer(formula = most.mp.corrupt ~ Nexis.s + legg + 
              secondhometot + totexp_excludehome +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige + 
              (1|constituency2), 
            data = subset(BESX_t3d, partymatch == 1), na.action = na.omit)

a5_12 <- lmer(formula = most.mp.corrupt ~   
              Nexis.s + legg + 
              secondhometot + totexp_excludehome + partymatch +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige + 
              age + educ + attention + 
              news + telegraph + 
              occup + soctrust + econ12gb  +
              (1|constituency2), 
            data = subset(BESX_t3d, partymatch == 1), na.action = na.omit)

#-----5 -  Tables: Spillovers: -----
stargazer(a5_1, a5_2, a5_3, a5_4, a5_5, a5_6, a5_7, a5_8, a5_9, a5_10, a5_11, a5_12, type = "text",
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          title = "Appendix 5", 
          out = "Appendix5a.html")
```

```{r Appendix F: Operationalisation of Implication}

BESX_f1 = BESX %>% 
  
  select(Nexis.s, legg, secondhometot, totexp_excludehome, incumbentstand.original, inner_london, distancelivedfromLondon, female, unemployed, se_managerial, density, redistrict_change, ukp54margin_notional, prestige, age, educ, attention, news, telegraph, occup, soctrust, econ12gb, exp.heard.loc.orig, exp.amount.loc.orig, constituency2, partymatch) %>% 
  
  filter(is.na(exp.heard.loc.orig) == F) 


a3_1 <- glmer(formula = exp.heard.loc.orig ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome + (1|constituency2), 
             family = binomial(link = "logit"), data = BESX_f1, 
             nAGQ = 0, na.action = na.omit)

a3_2 <- glmer(formula = exp.heard.loc.orig ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|constituency2), family = binomial(link = "logit"),
              data = BESX_f1, nAGQ = 0, na.action = na.omit)

a3_3 <- glmer(formula = exp.heard.loc.orig ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome +  partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige + 
                 age + educ + attention + 
                 news + telegraph + 
                 occup + soctrust + econ12gb  + 
                 (1|constituency2), family = binomial(link = "logit"),
              data = BESX_f1, nAGQ = 0, na.action = na.omit)

a3_4 <- lmer(formula = exp.amount.loc.orig ~ Nexis.s + legg + 
                secondhometot + totexp_excludehome + 
                + (1|constituency2), data = BESX_f1, 
               na.action = na.omit)

a3_5 <- lmer(formula = exp.amount.loc.orig ~ Nexis.s + legg + 
                secondhometot + totexp_excludehome + 
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige + 
                (1|constituency2),
              data = BESX_f1, na.action = na.omit)

a3_6 <- lmer(formula = exp.amount.loc.orig ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome +  partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige + 
                age + educ + attention + 
                news + telegraph + 
                occup + soctrust + econ12gb  + 
                (1|constituency2), 
              data = BESX_f1, na.action = na.omit)

stargazer(a3_1, a3_2, a3_3,
          a3_4, a3_5, a3_6, type = "text",
          
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          title = "Appendix 3", 
          out = "Appendix3.html")
```

```{r Appendix F: Differences by Political Knowledge}
#---Section 1: Eroding and Knowledge------
a6_1 <- lmer(formula = approvemp ~ Nexis.s + legg 
              + secondhometot + totexp_excludehome + attention + news + telegraph + Nexis.s*attention + legg*attention 
              + Nexis.s*news + legg*news + Nexis.s*telegraph + legg*telegraph  
              + (1|constituency2), 
              data = BESX_t2, 
              na.action = na.omit)

a6_2 <- lmer(formula = approvemp ~ Nexis.s + legg + 
                secondhometot + totexp_excludehome + attention + news + telegraph + Nexis.s*attention + legg*attention 
              + Nexis.s*news + legg*news + Nexis.s*telegraph + legg*telegraph +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige + 
                (1|constituency2), 
              data = BESX_t2, na.action = na.omit)

a6_3 <- lmer(formula = approvemp ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome + attention + news + telegraph + Nexis.s*attention + legg*attention 
              + Nexis.s*news + legg*news + Nexis.s*telegraph + legg*telegraph +
                partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige + 
                age + educ + 
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t2, na.action = na.omit)

stargazer(a6_1, a6_2, a6_3, type = "text",
          
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          title = "Appendix 6a", 
          out = "Appendix6a.html")
#---Section 2: Spillovers and Knowledge----
#-----1 -  Models: Politicians-----
a6_4 <- lmer(formula = trustplt ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = subset(BESX_t3a, attention > mean(BESX_t3a$attention, na.rm = TRUE)), 
               na.action = na.omit)

a6_5 <- lmer(formula = trustplt ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|constituency2), 
               data = subset(BESX_t3a, attention > mean(BESX_t3a$attention, na.rm = TRUE)), na.action = na.omit)

a6_6 <- lmer(formula = trustplt ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome + partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige + 
                 age + educ + attention +
                 news + telegraph + 
                 occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = subset(BESX_t3a, attention > mean(BESX_t3a$attention, na.rm = TRUE)), na.action = na.omit)

#-----2 -  Models: Parliament-----
a6_7 <- lmer(formula = trustprl ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = subset(BESX_t3b, attention > mean(BESX_t3b$attention, na.rm = TRUE)), 
               na.action = na.omit)

a6_8 <- lmer(formula = trustprl ~  Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                  female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = subset(BESX_t3b, attention > mean(BESX_t3b$attention, na.rm = TRUE)), na.action = na.omit)

a6_9 <- lmer(formula = trustprl ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige + 
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = subset(BESX_t3b, attention > mean(BESX_t3b$attention, na.rm = TRUE)), na.action = na.omit)
#-----3 -  Models: Satisfaction-----
BESX_t3c$satdem = as.numeric(BESX_t3c$satdem)

a6_10 <- lmer(formula = satdem ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = subset(BESX_t3c, attention > mean(BESX_t3c$attention, na.rm = TRUE)), 
               na.action = na.omit)

a6_11 <- lmer(formula = satdem ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|constituency2), 
               data = subset(BESX_t3c, attention > mean(BESX_t3c$attention, na.rm = TRUE)), na.action = na.omit)

a6_12 <- lmer(formula = satdem ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige + 
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = subset(BESX_t3c, attention > mean(BESX_t3c$attention, na.rm = TRUE)), na.action = na.omit)

#-----4 -  Models: Spillover Perceptions-----
BESX_t3d$most.mp.corrupt = as.numeric(BESX_t3d$most.mp.corrupt)


a6_13 <- lmer(formula = most.mp.corrupt ~ Nexis.s + legg 
            + secondhometot + totexp_excludehome
            + (1|constituency2), 
            data = subset(BESX_t3d, attention > mean(BESX_t3d$attention, na.rm = TRUE)), 
            na.action = na.omit)

a6_14 <- lmer(formula = most.mp.corrupt ~ Nexis.s + legg + 
              secondhometot + totexp_excludehome +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige + 
              (1|constituency2), 
            data = subset(BESX_t3d, attention > mean(BESX_t3d$attention, na.rm = TRUE)), na.action = na.omit)

a6_15 <- lmer(formula = most.mp.corrupt ~   
              Nexis.s + legg + 
              secondhometot + totexp_excludehome + partymatch +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige +
              age + educ + attention + 
              news + telegraph + 
              occup + soctrust + econ12gb  +
              (1|constituency2), 
            data = subset(BESX_t3d, attention > mean(BESX_t3d$attention, na.rm = TRUE)), na.action = na.omit)

#-----5 -  Tables: Spillovers: -----
stargazer(a6_4, a6_5, a6_6, a6_7, a6_8, a6_9, a6_10, a6_11, a6_12, a6_13, a6_14, a6_15, type = "text",
          
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          title = "Appendix 6b", 
          out = "Appendix6b.html")

#---Section 3: Spillovers and Newspaper Readership----
#-----1 -  Models: Politicians-----
a6_16 <- lmer(formula = trustplt ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = subset(BESX_t3a, news == 1), 
               na.action = na.omit)

a6_17 <- lmer(formula = trustplt ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = subset(BESX_t3a, news == 1), na.action = na.omit)

a6_18 <- lmer(formula = trustplt ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome + partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige + 
                 age + educ + attention +
                 news + telegraph + 
                 occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = subset(BESX_t3a, news == 1), na.action = na.omit)

#-----2 -  Models: Parliament-----
a6_19 <- lmer(formula = trustprl ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = subset(BESX_t3b, news == 1), 
               na.action = na.omit)

a6_20 <- lmer(formula = trustprl ~  Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                  female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|constituency2), 
               data = subset(BESX_t3b, news == 1), na.action = na.omit)

a6_21 <- lmer(formula = trustprl ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige + 
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = subset(BESX_t3b, news == 1), na.action = na.omit)
#-----3 -  Models: Satisfaction-----
BESX_t3c$satdem = as.numeric(BESX_t3c$satdem)

a6_22 <- lmer(formula = satdem ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = subset(BESX_t3c, news == 1), 
               na.action = na.omit)

a6_23 <- lmer(formula = satdem ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|constituency2), 
               data = subset(BESX_t3c, news == 1), na.action = na.omit)

a6_24 <- lmer(formula = satdem ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige + 
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = subset(BESX_t3c, news == 1), na.action = na.omit)

#-----4 -  Models: Spillover Perceptions-----
a6_25 <- lmer(formula = most.mp.corrupt ~ Nexis.s + legg 
            + secondhometot + totexp_excludehome
            + (1|constituency2), 
            data = subset(BESX_t3d, news == 1), 
            na.action = na.omit)

a6_26 <- lmer(formula = most.mp.corrupt ~ Nexis.s + legg + 
              secondhometot + totexp_excludehome +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige + 
              (1|constituency2), 
            data = subset(BESX_t3d, news == 1), na.action = na.omit)

a6_27 <- lmer(formula = most.mp.corrupt ~   
              Nexis.s + legg + 
              secondhometot + totexp_excludehome + partymatch +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige + 
              age + educ + attention + 
              news + telegraph + 
              occup + soctrust + econ12gb  +
              (1|constituency2), 
            data = subset(BESX_t3d, news == 1), na.action = na.omit)

#-----5 -  Tables: Spillovers: -----
stargazer(a6_16, a6_17, a6_18, a6_19, a6_20, a6_21, a6_22, a6_23, a6_24, a6_25, a6_26, a6_27, type = "text",
          
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          title = "Appendix 6d", 
          out = "Appendix6d.html")

```

```{r Appendix F: Endogenous Controls}
#------SECTION 1: LOADING AND TIDYING DATA------

#-----1 - Loading Data-----

BESL1 <- read.dta("Your file path for the BES 2005-2010 panel here")

#-----2 - Filtering BES Data-----
BESL <- data.frame(select(BESL1, 
                            besid, apcon201,
                          pre_q1, pre_q131, pre_q146,
                          seat, refno, 
                          vote05, y08_q63, 
                          y08_q65, y08_q48, 
                          y08_q57,
                            y09_q48, y09_q56, 
                            y09_q57, 
                            y09_q83, 
                          y09_q69, 
                          y09_q70, 
                          y09_q71, 
                          y09_q72, 
                          y09_q73,
                          aaq57, aaq58, aaq128, aaq71, aaq72, aaq80,
                          aaq142, aaq143, aaq159, aaq171, oyo_q93, 
                          bbq61, ccq128,
                          turn05, pre_q139, cam_q63, post_q51))

#-----3 - Renaming BES Variables-----

BESL <- BESL %>% 
  rename(
    turn05 = turn05,
    vote05 = vote05,
    ID = besid,
    region = pre_q1,
    soctrust05 = pre_q131,
    news05 = pre_q146,
    econ08 = y08_q48, 
    party08 = y08_q57, 
    attention08 = y08_q63,
    satdem06 = oyo_q93,
    satdem08 = y08_q65,
    satdem09 = y09_q48,
    satdem10cam = bbq61, 
    satdem10post = ccq128,
    satdem05pre = pre_q139, 
    satdem05cam = cam_q63, 
    satdem05post = post_q51,
    trustplt09 = y09_q56, 
    trustprl09 = y09_q57, 
    age09 = y09_q83,
    trustprl10= aaq57, 
    trustplt10 = aaq58,
    mpassist10 = aaq71,
    mpassistgood10 = aaq72,
    mpapprove10 = aaq80,
    satdem10pre = aaq128,
    exploc10 = aaq142, 
    explocscale10 = aaq143,
    educ10 = aaq159,
    occup10 = aaq171,
    constituency10 = apcon201,
    constituency09 = seat,
    refno = refno, 
    mostmpcorrupt = y09_q69, 
    expenseangry = y09_q70, 
    expenseunimportant = y09_q71,
    expenseresign = y09_q72,
    mostmpnotcorrupt = y09_q73
  )

#-----4 - Merging with Expenses Data-----
BESLP <- merge(BESL, EX, by.x = "refno", by.y = "RefnoLP", incomparables = NA)

#-----5 - Recoding Variables--------------------

BESLP <- BESLP %>% mutate(econ08 = 
                              recode(econ08, 
                                     "Got a lot better" = 1, 
                                     "Got a little better" = 0.75, 
                                     "Stayed the same" = 0.5, 
                                     "Got a little worse" = 0.25, 
                                     "Got a lot worse" = 0))

BESLP <- BESLP %>% mutate(mostmpcorrupt = 
                            recode(mostmpcorrupt, 
                                   "Strongly agree" = 1, 
                                   "Agree" = 0.75, 
                                   "Neither agree nor disagree" = 0.5, 
                                   "Disagree" = 0.25, 
                                   "Strongly disagree" = 0))

BESLP <- BESLP %>% mutate(mostmpnotcorrupt = 
                            recode(mostmpnotcorrupt, 
                                   "Strongly agree" = 1, 
                                   "Agree" = 0.75, 
                                   "Neither agree nor disagree" = 0.5, 
                                   "Disagree" = 0.25, 
                                   "Strongly disagree" = 0))

BESLP <- BESLP %>% mutate(mpapprove10 = 
                            recode(mpapprove10, 
                                   "Strongly agree" = 1, 
                                   "Agree" = 0.75, 
                                   "Neither agree nor disagree" = 0.5, 
                                   "Disagree" = 0.25, 
                                   "Strongly disagree" = 0))

BESLP <- BESLP %>% mutate(expenseangry = 
                            recode(expenseangry, 
                                   "Strongly agree" = 1, 
                                   "Agree" = 0.75, 
                                   "Neither agree nor disagree" = 0.5, 
                                   "Disagree" = 0.25, 
                                   "Strongly disagree" = 0))

BESLP <- BESLP %>% mutate(expenseunimportant = 
                            recode(expenseunimportant, 
                                   "Strongly agree" = 1, 
                                   "Agree" = 0.75, 
                                   "Neither agree nor disagree" = 0.5, 
                                   "Disagree" = 0.25, 
                                   "Strongly disagree" = 0))

BESLP <- BESLP %>% mutate(expenseresign = 
                            recode(expenseresign, 
                                   "Strongly agree" = 1, 
                                   "Agree" = 0.75, 
                                   "Neither agree nor disagree" = 0.5, 
                                   "Disagree" = 0.25, 
                                   "Strongly disagree" = 0))

BESLP <- BESLP %>% mutate(attention08 = 
                              recode(attention08, 
                                     "0-No attention" = 0,
                                     "1" = 0.1, "2" = 0.2, "3" = 0.3, "4" = 0.4, 
                                     "5" = 0.5, "6" = 0.6, "7" = 0.7, "8" = 0.8, "9" = 0.9,
                                     "10-Great deal" = 1))

BESLP <- BESLP %>% mutate(satdem08 = 
                              recode(satdem08, 
                                     "Very dissatisfied" = 0, 
                                     "A little dissatisfied" = 0.33, 
                                     "Fairly satisfied" = 0.66, 
                                     "Very satisfied" = 1))

BESLP <- BESLP %>% mutate(satdem09 = 
                            recode(satdem09, 
                                   "Very dissatisfied" = 0, 
                                   "A little dissatisfied" = 0.33, 
                                   "Fairly satisfied" = 0.66, 
                                   "Very satisfied" = 1))

BESLP <- BESLP %>% mutate(satdem10pre = 
                            recode(satdem10pre, 
                                   "Very dissatisfied" = 0, 
                                   "A little dissatisfied" = 0.33, 
                                   "Fairly satisfied" = 0.66, 
                                   "Very satisfied" = 1))

BESLP <- BESLP %>% mutate(satdem10cam = 
                            recode(satdem10cam, 
                                   "Very dissatisfied" = 0, 
                                   "A little dissatisfied" = 0.33, 
                                   "Fairly satisfied" = 0.66, 
                                   "Very satisfied" = 1))

BESLP <- BESLP %>% mutate(satdem10post = 
                            recode(satdem10post, 
                                   "Very dissatisfied" = 0, 
                                   "A little dissatisfied" = 0.33, 
                                   "Fairly satisfied" = 0.66, 
                                   "Very satisfied" = 1))


BESLP <- BESLP %>% mutate(satdem05cam = 
                            recode(satdem05cam, 
                                   "Very dissatisfied" = 0, 
                                   "A little dissatisfied" = 0.33, 
                                   "Fairly satisfied" = 0.66, 
                                   "Very satisfied" = 1))

BESLP <- BESLP %>% mutate(satdem05pre = 
                            recode(satdem05pre, 
                                   "Very dissatisfied" = 0, 
                                   "A little dissatisfied" = 0.33, 
                                   "Fairly satisfied" = 0.66, 
                                   "Very satisfied" = 1))

BESLP <- BESLP %>% mutate(satdem05post = 
                            recode(satdem05post, 
                                   "Very dissatisfied" = 0, 
                                   "A little dissatisfied" = 0.33, 
                                   "Fairly satisfied" = 0.66, 
                                   "Very satisfied" = 1))

BESLP <- BESLP %>% mutate(satdem06 = 
                            recode(satdem06, 
                                   "Very dissatisfied" = 0, 
                                   "A little dissatisfied" = 0.33, 
                                   "Fairly satisfied" = 0.66, 
                                   "Very satisfied" = 1))


BESLP <- BESLP %>% mutate(trustplt09 = 
                              recode(trustplt09, 
                                     "0-No trust" = 0,
                                     "1" = 0.1, "2" = 0.2, "3" = 0.3, "4" = 0.4, 
                                     "5" = 0.5, "6" = 0.6, "7" = 0.7, "8" = 0.8, "9" = 0.9,
                                     "10-Great deal" = 1))

BESLP <- BESLP %>% mutate(trustprl09 = 
                              recode(trustprl09, 
                                     "0-No trust" = 0,
                                     "1" = 0.1, "2" = 0.2, "3" = 0.3, "4" = 0.4, 
                                     "5" = 0.5, "6" = 0.6, "7" = 0.7, "8" = 0.8, "9" = 0.9,
                                     "10-Great deal" = 1))

BESLP <- BESLP %>% mutate(trustplt10 = 
                            recode(trustplt10, 
                                   "0-No trust" = 0,
                                   "1" = 0.1, "2" = 0.2, "3" = 0.3, "4" = 0.4, 
                                   "5" = 0.5, "6" = 0.6, "7" = 0.7, "8" = 0.8, "9" = 0.9,
                                   "10-Great deal trust" = 1))

BESLP <- BESLP %>% mutate(trustprl10 = 
                            recode(trustprl10, 
                                   "0-No trust" = 0,
                                   "1" = 0.1, "2" = 0.2, "3" = 0.3, "4" = 0.4, 
                                   "5" = 0.5, "6" = 0.6, "7" = 0.7, "8" = 0.8, "9" = 0.9,
                                   "10-Great deal trust" = 1))

BESLP <- BESLP %>% mutate(news05 = 
                              recode(news05, 
                                     "Everyday" = 1,
                                     "Sometimes" = 0.5,
                                     "Not at all" = 0))

BESLP$age09 <- as.numeric(BESLP$age09)


BESLP <- BESLP %>% mutate(soctrust05 = 
                              recode(soctrust05, 
                                     "0.00" = 0,
                                     "12.00" = 0,
                                     "10.00" = 1))

BESLP <- BESLP %>% mutate(exploc10 = 
                              recode(exploc10, 
                                     "Yes" = 1, 
                                     "Don't know" = 0,
                                     "No" = 0))

BESLP <- BESLP %>% mutate(explocscale10 = 
                              recode(explocscale10, 
                                     "Not asked" = 0,
                                     "0-small amount" = 0,
                                     "1" = 0.1, "2" = 0.2, "3" = 0.3, "4" = 0.4, 
                                     "5" = 0.5, "6" = 0.6, "7" = 0.7, "8" = 0.8, "9" = 0.9,
                                     "10-very large amount" = 1))

BESLP <- BESLP %>% mutate(test = 
                              recode(educ10, 
                                     "Postgraduate degree" = 1,
                                     "Teaching qualification (not degree)" = 15/17,
                                     "University or CNAA first degree, e.g, BA, BSc" = 16/17, 
                                     "Nursing qualification (e.g., SEN, SRC, SCM, RGC)" = 13/17,
                                     "Clerical and commercial qualification (e.g., typing, shortha" = 3/17,
                                     "Recognised trade apprenticeship completed" = 2/17,
                                     "Other technical, professional or higher qualification" = 1/17,
                                     "University or CNAA diploma" = 15/17,
                                     "Higher National Certificate (HNC) or Higher National Diploma" = 12/17,
                                     "GCE A level, S level, A2 level, AS level, International Bacc" = 11/17,
                                     "Scottish Higher/Higher Still Grades, Scottish SLC/SUPE at Hi" = 10/17,
                                     "Ordinary National Certificate (ONC) or Diploma (OND), City &" = 9/17,
                                     "Scottish Ordinary Bands A-C or pass, Scottish Standard Grade" = 7/17,
                                     "GCSE A*-C, CSE grade 1, GCE O level grade A -C, School Cer" = 8/17,
                                     "City & Guilds level 2 (Craft/Intermediate/Ordinary) or Scotv" = 5/17,
                                     "GCSE grades D-G, CSE grades 2-5, GCE O level grade D -E, S" = 6/17,
                                     "City & Guilds level 1, Scotvec National Certificate Modules," = 4/17))

BESLP <- BESLP %>% mutate(occup10 = 
                              recode(occup10, 
                                     "Professional or higher technical work (work that requires at" = 1,
                                     "Manager or Senior Administrator (e.g. company director, fina" = 6/7, 
                                     "Clerical (e.g. clerk, secretary)" = 5/7, 
                                     "Sales or Services (e.g. commercial traveller, shop assistant" = 4/7, 
                                     "Small Business Owner (e.g. shop owner, small builder, restau" = 3/7, 
                                     "Foreman or Supervisor of Other Workers (e.g. building site f" = 2/7, 
                                     "Skilled Manual Work (e.g. plumber, electrician, fitter, trai" = 1/7, 
                                     "Semi-Skilled or Unskilled Manual Work (e.g. machine operator" = 0, 
                                     "other" = 3.5/7))

#-----6 - Rescaling Variables-----
BESLP$legg = log(1 + BESLP$legg)
BESLP$legg = BESLP$legg/10

BESLP$totexp_excludehome = log(1 + BESLP$totexp_excludehome)
BESLP$totexp_excludehome = BESLP$totexp_excludehome/14

BESLP$secondhometot = log(1 + BESLP$secondhometot)
BESLP$secondhometot = BESLP$secondhometot/11

BESLP$redistrict_change = BESLP$redistrict_change/100

BESLP$se_managerial = BESLP$se_managerial/100

BESLP$ukp54margin_notional = BESLP$ukp54margin_notional/100

BESLP$unemployed = BESLP$unemployed/100

BESLP$density = BESLP$density/100

BESLP$distancelivedfromLondon = BESLP$distancelivedfromLondon/100

BESLP$tenure = BESLP$tenure/100

BESLP$age.x = BESLP$age.x/100

BESLP$prescandal.article.count = BESLP$prescandal.article.count/100

BESLP$Nexis.s = as.numeric(scale(BESLP$Nexis.s)) 
BESLP$Nexis.s09 = as.numeric(scale(BESLP$Nexis.s09))
BESLP$legg = as.numeric(scale(BESLP$legg))
BESLP$secondhometot = as.numeric(scale(BESLP$secondhometot))
BESLP$totexp_excludehome = as.numeric(scale(BESLP$totexp_excludehome))

#-----7 - Creating Party Match Variable-----
BESLP$party <- as.factor(BESLP$party)
BESLP$party[BESLP$party == "Liberal Democrats"] = "Liberal Democrat"

BESLP$partymatch = 0
BESLP$partymatch[BESLP$party08 == "Conservative"
                 & BESLP$party == "Conservative Party"] = 1
BESLP$partymatch[BESLP$party08 == "Labour"
                 & BESLP$party == "Labour Party"] = 1
BESLP$partymatch[BESLP$party08 == "Liberal Democrat"
                 & BESLP$party == "Liberal Democrat"] = 1

BESLP$prestige = BESLP$frontbench0809 + BESLP$Pre.Hon + BESLP$Post.Hon


#-----SECTION 2: PERCEPTIONS-----
#-----8 - Multilevel Models: Local Perceptions-----

BESLP_t1 = BESLP %>% 
  
  select(explocscale10, exploc10, Nexis.s, legg, secondhometot, totexp_excludehome, female, inner_london, incumbentstand.original, distancelivedfromLondon, unemployed, se_managerial, density, redistrict_change, ukp54margin_notional, redistrict_change, prestige, age09, attention08, econ08, refno) %>% 
  
  na.omit()

a7_1 <- lmer(formula = explocscale10 ~   
                 Nexis.s + legg + 
                 secondhometot +
                 totexp_excludehome +
                 (1|refno), 
               data = BESLP_t1, na.action = na.omit)

a7_2 <- lmer(formula = explocscale10 ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|refno),
               data = BESLP_t1, na.action = na.omit)

a7_3 <- lmer(formula = explocscale10 ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 age09 + attention08 +
                  econ08 +
                 (1|refno), 
               data = BESLP_t1, na.action = na.omit)

a7_4 <- glmer(formula = exploc10 ~   
                 Nexis.s + legg + 
                 secondhometot +
                 totexp_excludehome +
                 (1|refno), family = binomial(link = "logit"),
               data = BESLP_t1, nAGQ = 0, na.action = na.omit)

a7_5 <- glmer(formula = exploc10 ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|refno), family = binomial(link = "logit"),
               data = BESLP_t1, nAGQ = 0, na.action = na.omit)

a7_6 <- glmer(formula = exploc10 ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 age09 + attention08 +
                  econ08 +
                 (1|refno), family = binomial(link = "logit"),
               data = BESLP_t1, nAGQ = 0, na.action = na.omit)
#Note: exclude some controls to ensure convergence. 

#-----9 - Summarising Models: Local Perceptions-----
stargazer(a7_1, a7_2, a7_3, a7_4, a7_5, a7_6, star.char = c("*", "**"), type = "text",
          star.cutoffs = c(0.05, 0.01), title = "Appendix 7a", out = "Appendix7a.html")

#-----SECTION 3: ERODING EFFECTS-----
#-----10 - Multilevel Models: Eroding Effects-----

BESLP_t2 = BESLP %>% 
  
  select(mpapprove10, Nexis.s, legg, secondhometot, totexp_excludehome, female, inner_london, incumbentstand.original, distancelivedfromLondon, unemployed, se_managerial, density, redistrict_change, ukp54margin_notional, redistrict_change, prestige, age09, attention08, econ08, refno) %>% 
  
  na.omit()

a7_7 <- lmer(formula = mpapprove10 ~   
                Nexis.s + legg + 
                secondhometot +
                totexp_excludehome +
                (1|refno), 
              data = BESLP_t2, na.action = na.omit)

a7_8 <- lmer(formula = mpapprove10 ~   
                Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                (1|refno),
              data = BESLP_t2, na.action = na.omit)

a7_9 <- lmer(formula = mpapprove10 ~   
                Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                age09 + attention08 +
                  econ08 + 
                (1|refno), 
              data = BESLP_t2, na.action = na.omit)

#-----11 - Summarising Models: Eroding Effects-----
stargazer(a7_7, a7_8, a7_9, type = "text",
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), title = "Appendix 7b", out = "Appendix7b.html")
#-----SECTION 4: SPILLOVER EFFECTS------
#-----12 - Multilevel Models: Spillover Effects: Trust in Politicians-----

BESLP_t3 = BESLP %>% 
  
  select(trustplt10,trustprl10,satdem10pre, mostmpcorrupt,Nexis.s, legg, secondhometot, totexp_excludehome, female, inner_london, incumbentstand.original, distancelivedfromLondon, unemployed, se_managerial, density, redistrict_change, ukp54margin_notional, redistrict_change, prestige, age09, attention08, econ08, refno, Constituency2) %>% 
  
  na.omit()

a7_13 <- lmer(formula = trustplt10 ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|Constituency2), 
               data = BESLP_t3, 
               na.action = na.omit)

a7_14 <- lmer(formula = trustplt10 ~  Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|Constituency2), 
               data = BESLP_t3, na.action = na.omit)

a7_15 <- lmer(formula = trustplt10 ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 age09 + attention08 +
                  econ08 +
                 (1|refno), 
               data = BESLP_t3, na.action = na.omit)
#-----13 - Multilevel Models: Spillover Effects: Trust in Parliament-----
a7_16 <- lmer(formula = trustprl10 ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|Constituency2), 
               data = BESLP_t3, 
               na.action = na.omit)

a7_17 <- lmer(formula = trustprl10 ~  Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|Constituency2), 
               data = BESLP_t3, na.action = na.omit)

a7_18 <- lmer(formula = trustprl10 ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 age09 + attention08 +
                  econ08 +
                 (1|Constituency2), 
               data = BESLP_t3, na.action = na.omit)
#-----14 - Multilevel Models: Spillover Effects: Satisfaction with Democracy-----
a7_19 <- lmer(formula = satdem10pre ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|Constituency2), 
               data = BESLP_t3, 
               na.action = na.omit)

a7_20 <- lmer(formula = satdem10pre ~  Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|Constituency2), 
               data = BESLP_t3, na.action = na.omit)

a7_21 <- lmer(formula = satdem10pre ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 age09 + attention08 +
                  econ08 +
                 (1|Constituency2), 
               data = BESLP_t3, na.action = na.omit)

#-----SECTION 5: MECHANISM TESTS:
#-----15 - Multilevel Models: Spillover Perceptions-----
a7_22 <- lmer(formula = mostmpcorrupt ~ Nexis.s + legg 
                + secondhometot + totexp_excludehome
                + (1|Constituency2), 
                data = BESLP_t3, 
                na.action = na.omit)

a7_23 <- lmer(formula = mostmpcorrupt ~  Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                  (1|Constituency2), 
                data = BESLP_t3, na.action = na.omit)

a7_24 <- lmer(formula = mostmpcorrupt ~   
                  Nexis.s + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                  age09 + attention08 +
                  econ08 +
                  (1|Constituency2), 
                data = BESLP_t3, na.action = na.omit)
#-----16 - Tables: Spillover Effects: -----
stargazer(a7_13, a7_14, a7_15, a7_16, a7_17, a7_18,a7_19, a7_20, a7_21, a7_22, a7_23, a7_24, type = "text",
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          title = "Appendix 7c", 
          out = "Appendix7c.html")

```

```{r Appendix F: Scandal Fatigue}
#-----1 - Trust in Politicians-----

BESLP_t3 = BESLP %>% 
  
  select(trustplt10,trustprl10,satdem10pre, mostmpcorrupt,Nexis.s, legg, secondhometot, totexp_excludehome, female, inner_london, incumbentstand.original, distancelivedfromLondon, unemployed, se_managerial, density, redistrict_change, ukp54margin_notional, redistrict_change, prestige, age09, attention08, econ08, refno, Constituency2, trustplt09, trustprl09, satdem09, Nexis.s09) %>% 
  
  na.omit()

a8_1 <- lmer(formula = trustplt09 ~ Nexis.s09 + legg 
               + secondhometot + totexp_excludehome
               + (1|Constituency2), 
               data = BESLP_t3, 
               na.action = na.omit)

a8_2 <- lmer(formula = trustplt09 ~  Nexis.s09 + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|Constituency2), 
               data = BESLP_t3, na.action = na.omit)

a8_3 <- lmer(formula = trustplt09 ~   
                 Nexis.s09 + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 age09 + attention08 +
                  econ08 +
                 (1|Constituency2), 
               data = BESLP_t3, na.action = na.omit)
#-----2 - Trust in Parliament-----
a8_4 <- lmer(formula = trustprl09 ~ Nexis.s09 + legg 
               + secondhometot + totexp_excludehome
               + (1|Constituency2), 
               data = BESLP_t3, 
               na.action = na.omit)

a8_5 <- lmer(formula = trustprl09 ~  Nexis.s09 + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|Constituency2), 
               data = BESLP_t3, na.action = na.omit)

a8_6 <- lmer(formula = trustprl09 ~   
                 Nexis.s09 + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 age09 + attention08 +
                  econ08 +
                 (1|Constituency2), 
               data = BESLP_t3, na.action = na.omit)
#-----3 - Satisfaction with Democracy-----
a8_7 <- lmer(formula = satdem09 ~ Nexis.s09 + legg 
               + secondhometot + totexp_excludehome
               + (1|Constituency2), 
               data = BESLP_t3, 
               na.action = na.omit)

a8_8 <- lmer(formula = satdem09 ~  Nexis.s09 + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|Constituency2), 
               data = BESLP_t3, na.action = na.omit)

a8_9 <- lmer(formula = satdem09 ~ Nexis.s09 + legg + 
                 secondhometot + totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 age09 + attention08 +
                  econ08 +
                 (1|Constituency2), 
               data = BESLP_t3, na.action = na.omit)

#-----16 - Tables: Spillover Effects: -----
stargazer(a8_1, a8_2, a8_3, a8_4, a8_5, a8_6, a8_7, a8_8, a8_9, type = "text",
           star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          title = "Appendix 8", 
          out = "Appendix8.html")
```

```{r Appendix F: Boundary Changes}

BESX_t3 = BESX %>% 
  
  select(Nexis.s, legg, secondhometot, totexp_excludehome, incumbentstand.original, inner_london, distancelivedfromLondon, female, unemployed, se_managerial, density, redistrict_change, ukp54margin_notional, prestige, age, educ, attention, news, telegraph, occup, soctrust, econ12gb, trustplt, trustprl, satdem, most.mp.corrupt, constituency2, partymatch) %>% 
  
  na.omit() 

#-----1 -  Models: Politicians-----
a9_1 <- lmer(formula = trustplt ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = subset(BESX_t3, redistrict_change < 0.5), 
               na.action = na.omit)

a9_2 <- lmer(formula = trustplt ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|constituency2), 
               data = subset(BESX_t3, redistrict_change < 0.5), na.action = na.omit)

a9_3 <- lmer(formula = trustplt ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome + partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige + 
                 age + educ + attention +
                 news + telegraph + 
                 occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = subset(BESX_t3, redistrict_change < 0.5), na.action = na.omit)

#-----2 -  Models: Parliament-----
a9_4 <- lmer(formula = trustprl ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = subset(BESX_t3, redistrict_change < 0.5), 
               na.action = na.omit)

a9_5 <- lmer(formula = trustprl ~  Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                  female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|constituency2), 
               data = subset(BESX_t3, redistrict_change < 0.5), na.action = na.omit)

a9_6 <- lmer(formula = trustprl ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige + 
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = subset(BESX_t3, redistrict_change < 0.5), na.action = na.omit)
#-----3 -  Models: Satisfaction-----
BESX_t3$satdem = as.numeric(BESX_t3$satdem)

a9_7 <- lmer(formula = satdem ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = subset(BESX_t3, redistrict_change < 0.5), 
               na.action = na.omit)

a9_8 <- lmer(formula = satdem ~ Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige + 
                 (1|constituency2), 
               data = subset(BESX_t3, redistrict_change < 0.5), na.action = na.omit)

a9_9 <- lmer(formula = satdem ~   
                Nexis.s + legg + 
                secondhometot + totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige + 
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = subset(BESX_t3, redistrict_change < 0.5), na.action = na.omit)

BESX$satdem = as.factor(BESX$satdem)

#-----4 -  Models: Spillover Perceptions-----
a9_10 <- lmer(formula = most.mp.corrupt ~ Nexis.s + legg 
            + secondhometot + totexp_excludehome
            + (1|constituency2), 
            data = subset(BESX_t3, redistrict_change < 0.5), 
            na.action = na.omit)

a9_11 <- lmer(formula = most.mp.corrupt ~ Nexis.s + legg + 
              secondhometot + totexp_excludehome +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige + 
              (1|constituency2), 
            data = subset(BESX_t3, redistrict_change < 0.5), na.action = na.omit)

a9_12 <- lmer(formula = most.mp.corrupt ~   
              Nexis.s + legg + 
              secondhometot + totexp_excludehome + partymatch +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige + 
              age + educ + attention + 
              news + telegraph + 
              occup + soctrust + econ12gb  +
              (1|constituency2), 
            data = subset(BESX_t3, redistrict_change < 0.5), na.action = na.omit)

#-----5 -  Tables: Spillovers: -----
stargazer(a9_1, a9_2, a9_3, a9_4, a9_5, a9_6, a9_7, a9_8, a9_9, a9_10, a9_11, a9_12, type = "text",
           star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01),
          title = "Appendix 9a", 
          out = "Appendix9a.html")
```

```{r Appendix F: Attributions with Media only}
t1_1 <- glmer(formula = exp.heard.loc ~ Nexis.s   
             + (1|constituency2), 
             family = binomial(link = "logit"), data = BESX_t1, 
             nAGQ = 0, na.action = na.omit)

t1_2 <- glmer(formula = exp.heard.loc ~ Nexis.s + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), family = binomial(link = "logit"),
              data = BESX_t1, nAGQ = 0, na.action = na.omit)

t1_3 <- glmer(formula = exp.heard.loc ~   
                 Nexis.s +  partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige +
                 age + educ + attention + 
                 news + telegraph + 
                 occup + soctrust + econ12gb  + 
                 (1|constituency2), family = binomial(link = "logit"),
              data = BESX_t1, nAGQ = 0, na.action = na.omit)

t1_4 <- lmer(formula = exp.amount.loc ~ Nexis.s  + 
                + (1|constituency2), data = BESX_t1, 
               na.action = na.omit)

t1_5 <- lmer(formula = exp.amount.loc ~ Nexis.s  + 
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                (1|constituency2),
              data = BESX_t1, na.action = na.omit)

t1_6 <- lmer(formula = exp.amount.loc ~   
                Nexis.s +  partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige + 
                age + educ + attention + 
                news + telegraph + 
                occup + soctrust + econ12gb  + 
                (1|constituency2), 
              data = BESX_t1, na.action = na.omit)

stargazer(t1_4, t1_5, t1_6, t1_1, t1_2, t1_3, type = "text",
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          out = "Table1_media.html")
```

```{r Appendix F: Attributions with Legg only}
t1_1 <- glmer(formula = exp.heard.loc ~ legg   
             + (1|constituency2), 
             family = binomial(link = "logit"), data = BESX_t1, 
             nAGQ = 0, na.action = na.omit)

t1_2 <- glmer(formula = exp.heard.loc ~ legg + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), family = binomial(link = "logit"),
              data = BESX_t1, nAGQ = 0, na.action = na.omit)

t1_3 <- glmer(formula = exp.heard.loc ~   
                 legg +  partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige +
                 age + educ + attention + 
                 news + telegraph + 
                 occup + soctrust + econ12gb  + 
                 (1|constituency2), family = binomial(link = "logit"),
              data = BESX_t1, nAGQ = 0, na.action = na.omit)

t1_4 <- lmer(formula = exp.amount.loc ~ legg  + 
                + (1|constituency2), data = BESX_t1, 
               na.action = na.omit)

t1_5 <- lmer(formula = exp.amount.loc ~ legg  + 
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                (1|constituency2),
              data = BESX_t1, na.action = na.omit)

t1_6 <- lmer(formula = exp.amount.loc ~   
                legg +  partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige + 
                age + educ + attention + 
                news + telegraph + 
                occup + soctrust + econ12gb  + 
                (1|constituency2), 
              data = BESX_t1, na.action = na.omit)

stargazer(t1_4, t1_5, t1_6, t1_1, t1_2, t1_3, type = "text",
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          out = "Table1_legg.html")
```

```{r Appendix F: Attributions with Second Home only}
t1_1 <- glmer(formula = exp.heard.loc ~ secondhometot   
             + (1|constituency2), 
             family = binomial(link = "logit"), data = BESX_t1, 
             nAGQ = 0, na.action = na.omit)

t1_2 <- glmer(formula = exp.heard.loc ~ secondhometot + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), family = binomial(link = "logit"),
              data = BESX_t1, nAGQ = 0, na.action = na.omit)

t1_3 <- glmer(formula = exp.heard.loc ~   
                 secondhometot +  partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige +
                 age + educ + attention + 
                 news + telegraph + 
                 occup + soctrust + econ12gb  + 
                 (1|constituency2), family = binomial(link = "logit"),
              data = BESX_t1, nAGQ = 0, na.action = na.omit)

t1_4 <- lmer(formula = exp.amount.loc ~ secondhometot  + 
                + (1|constituency2), data = BESX_t1, 
               na.action = na.omit)

t1_5 <- lmer(formula = exp.amount.loc ~ secondhometot  + 
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                (1|constituency2),
              data = BESX_t1, na.action = na.omit)

t1_6 <- lmer(formula = exp.amount.loc ~   
                secondhometot +  partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige + 
                age + educ + attention + 
                news + telegraph + 
                occup + soctrust + econ12gb  + 
                (1|constituency2), 
              data = BESX_t1, na.action = na.omit)

stargazer(t1_4, t1_5, t1_6, t1_1, t1_2, t1_3, type = "text",
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          out = "Table1_secondhome.html")
```

```{r Appendix F: Attributions with Other Expenses only}
t1_1 <- glmer(formula = exp.heard.loc ~ totexp_excludehome   
             + (1|constituency2), 
             family = binomial(link = "logit"), data = BESX_t1, 
             nAGQ = 0, na.action = na.omit)

t1_2 <- glmer(formula = exp.heard.loc ~ totexp_excludehome + 
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), family = binomial(link = "logit"),
              data = BESX_t1, nAGQ = 0, na.action = na.omit)

t1_3 <- glmer(formula = exp.heard.loc ~   
                 totexp_excludehome +  partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige +
                 age + educ + attention + 
                 news + telegraph + 
                 occup + soctrust + econ12gb  + 
                 (1|constituency2), family = binomial(link = "logit"),
              data = BESX_t1, nAGQ = 0, na.action = na.omit)

t1_4 <- lmer(formula = exp.amount.loc ~ totexp_excludehome  + 
                + (1|constituency2), data = BESX_t1, 
               na.action = na.omit)

t1_5 <- lmer(formula = exp.amount.loc ~ totexp_excludehome  + 
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                (1|constituency2),
              data = BESX_t1, na.action = na.omit)

t1_6 <- lmer(formula = exp.amount.loc ~   
                totexp_excludehome +  partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige + 
                age + educ + attention + 
                news + telegraph + 
                occup + soctrust + econ12gb  + 
                (1|constituency2), 
              data = BESX_t1, na.action = na.omit)

stargazer(t1_4, t1_5, t1_6, t1_1, t1_2, t1_3, type = "text",
          star.char = c("*", "**"), 
          star.cutoffs = c(0.05, 0.01), 
          out = "Table1_otherexpense.html")
```

```{r Appendix F: Eroding with Media only}
t2_4 <- lmer(formula = approvemp ~ Nexis.s 
              + (1|constituency2), 
              data = BESX_t2, 
              na.action = na.omit)

t2_5 <- lmer(formula = approvemp ~ Nexis.s +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige +
                (1|constituency2), 
              data = BESX_t2, na.action = na.omit)

t2_6 <- lmer(formula = approvemp ~   
                 Nexis.s + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t2, na.action = na.omit)

stargazer(t2_4, t2_5, t2_6, type = "text",
          star.char = c("*", "**"), 
          star.cutoffs = c(0.05, 0.01),
          title = "Table 2", 
          out = "Table2_media.html")
```

```{r Appendix F: Eroding with Legg only}
BESX_t2$approvemp<-as.numeric(BESX_t2$approvemp)

t2_4 <- lmer(formula = approvemp ~ legg + 
              + (1|constituency2), 
              data = BESX_t2, 
              na.action = na.omit)

t2_5 <- lmer(formula = approvemp ~ legg +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige +
                (1|constituency2), 
              data = BESX_t2, na.action = na.omit)

t2_6 <- lmer(formula = approvemp ~   
                 legg + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t2, na.action = na.omit)

stargazer(t2_4, t2_5, t2_6, type = "text",
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          title = "Table 2", 
          out = "Table2_legg.html")
```

```{r Appendix F: Eroding with Second Home only}

t2_4 <- lmer(formula = approvemp ~ secondhometot 
              + (1|constituency2), 
              data = BESX_t2, 
              na.action = na.omit)

t2_5 <- lmer(formula = approvemp ~ secondhometot +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige +
                (1|constituency2), 
              data = BESX_t2, na.action = na.omit)

t2_6 <- lmer(formula = approvemp ~   
                 secondhometot + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t2, na.action = na.omit)

stargazer(t2_4, t2_5, t2_6, type = "text",
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          title = "Table 2", 
          out = "Table2_secondhome.html")
```

```{r Appendix F: Eroding with Other Expenses only}

t2_4 <- lmer(formula = approvemp ~ totexp_excludehome 
              + (1|constituency2), 
              data = BESX_t2, 
              na.action = na.omit)

t2_5 <- lmer(formula = approvemp ~ totexp_excludehome +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change + 
                ukp54margin_notional + prestige +
                (1|constituency2), 
              data = BESX_t2, na.action = na.omit)

t2_6 <- lmer(formula = approvemp ~   
                 totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t2, na.action = na.omit)

stargazer(t2_4, t2_5, t2_6, type = "text",
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          title = "Table 2", 
          out = "Table2_otherexpense.html")
```

```{r Appendix F: Spillovers with Media Only} 

#-----1 -  Politicians-----
t3_1 <- lmer(formula = trustplt ~ Nexis.s
               + (1|constituency2), 
               data = BESX_t3a, 
               na.action = na.omit)

t3_2 <- lmer(formula = trustplt ~ Nexis.s +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3a, na.action = na.omit)

t3_3 <- lmer(formula = trustplt ~   
                 Nexis.s+ partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige +
                 age + educ + attention +
                 news + telegraph + 
                 occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t3a, na.action = na.omit)

#-----2 -  Parliament-----
t3_4 <- lmer(formula = trustprl ~ Nexis.s
               + (1|constituency2), 
               data = BESX_t3b, 
               na.action = na.omit)

t3_5 <- lmer(formula = trustprl ~  Nexis.s +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                  female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3b, na.action = na.omit)

t3_6 <- lmer(formula = trustprl ~ Nexis.s + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t3b, na.action = na.omit)
#-----3 -  Satisfaction-----
BESX_t3$satdem = as.numeric(BESX_t3$satdem)

t3_7 <- lmer(formula = satdem ~ Nexis.s
               + (1|constituency2), 
               data = BESX_t3c, 
               na.action = na.omit)

t3_8 <- lmer(formula = satdem ~ Nexis.s +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3c, na.action = na.omit)

t3_9 <- lmer(formula = satdem ~   
                Nexis.s + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t3c, na.action = na.omit)
#-----4 -  Spillover Perceptions-----
BESX_t3$most.mp.corrupt <- as.numeric(BESX_t3$most.mp.corrupt)
t3_10 <- lmer(formula = most.mp.corrupt ~ Nexis.s
            + (1|constituency2), 
            data = BESX_t3d, 
            na.action = na.omit)

t3_11 <- lmer(formula = most.mp.corrupt ~ Nexis.s +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige +
              (1|constituency2), 
            data = BESX_t3d, na.action = na.omit)

t3_12 <- lmer(formula = most.mp.corrupt ~ Nexis.s + partymatch +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige +
              age + educ + attention + 
              news + telegraph + 
              occup + soctrust + econ12gb  +
              (1|constituency2), 
            data = BESX_t3d, na.action = na.omit)
#-----5 -  Tables: Spillovers: ----
stargazer(t3_1, t3_2, t3_3, 
          t3_4, t3_5, t3_6, 
          t3_7, t3_8, t3_9, 
          t3_10, t3_11, t3_12, type = "text",
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          out = "Table3_Media.html")

```

```{r Appendix F: Spillovers with Legg Only} 

#-----1 -  Politicians-----
t3_1 <- lmer(formula = trustplt ~ legg
               + (1|constituency2), 
               data = BESX_t3a, 
               na.action = na.omit)

t3_2 <- lmer(formula = trustplt ~ legg +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3a, na.action = na.omit)

t3_3 <- lmer(formula = trustplt ~   
                 legg+ partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige +
                 age + educ + attention +
                 news + telegraph + 
                 occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t3a, na.action = na.omit)

#-----2 -  Parliament-----
t3_4 <- lmer(formula = trustprl ~ legg
               + (1|constituency2), 
               data = BESX_t3b, 
               na.action = na.omit)

t3_5 <- lmer(formula = trustprl ~  legg +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                  female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3b, na.action = na.omit)

t3_6 <- lmer(formula = trustprl ~ legg + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t3b, na.action = na.omit)
#-----3 -  Satisfaction-----
BESX_t3$satdem = as.numeric(BESX_t3$satdem)

t3_7 <- lmer(formula = satdem ~ legg
               + (1|constituency2), 
               data = BESX_t3c, 
               na.action = na.omit)

t3_8 <- lmer(formula = satdem ~ legg +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3c, na.action = na.omit)

t3_9 <- lmer(formula = satdem ~   
                legg + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t3c, na.action = na.omit)
#-----4 -  Spillover Perceptions-----
BESX_t3$most.mp.corrupt <- as.numeric(BESX_t3$most.mp.corrupt)
t3_10 <- lmer(formula = most.mp.corrupt ~ legg
            + (1|constituency2), 
            data = BESX_t3d, 
            na.action = na.omit)

t3_11 <- lmer(formula = most.mp.corrupt ~ legg +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige +
              (1|constituency2), 
            data = BESX_t3d, na.action = na.omit)

t3_12 <- lmer(formula = most.mp.corrupt ~ legg + partymatch +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige +
              age + educ + attention + 
              news + telegraph + 
              occup + soctrust + econ12gb  +
              (1|constituency2), 
            data = BESX_t3d, na.action = na.omit)
#-----5 -  Tables: Spillovers: ----
stargazer(t3_1, t3_2, t3_3, 
          t3_4, t3_5, t3_6, 
          t3_7, t3_8, t3_9, type = "text",
          t3_10, t3_11, t3_12, 
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          out = "Table3_Legg.html")

```

```{r Appendix F: Spillovers with Second Home Only} 

#-----1 -  Politicians-----
t3_1 <- lmer(formula = trustplt ~ secondhometot
               + (1|constituency2), 
               data = BESX_t3a, 
               na.action = na.omit)

t3_2 <- lmer(formula = trustplt ~ secondhometot +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3a, na.action = na.omit)

t3_3 <- lmer(formula = trustplt ~   
                 secondhometot+ partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige +
                 age + educ + attention +
                 news + telegraph + 
                 occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t3a, na.action = na.omit)

#-----2 -  Parliament-----
t3_4 <- lmer(formula = trustprl ~ secondhometot
               + (1|constituency2), 
               data = BESX_t3b, 
               na.action = na.omit)

t3_5 <- lmer(formula = trustprl ~  secondhometot +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                  female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3b, na.action = na.omit)

t3_6 <- lmer(formula = trustprl ~ secondhometot + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t3b, na.action = na.omit)
#-----3 -  Satisfaction-----

t3_7 <- lmer(formula = satdem ~ secondhometot
               + (1|constituency2), 
               data = BESX_t3c, 
               na.action = na.omit)

t3_8 <- lmer(formula = satdem ~ secondhometot +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3c, na.action = na.omit)

t3_9 <- lmer(formula = satdem ~   
                secondhometot + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t3c, na.action = na.omit)
#-----4 -  Spillover Perceptions-----
t3_10 <- lmer(formula = most.mp.corrupt ~ secondhometot
            + (1|constituency2), 
            data = BESX_t3d, 
            na.action = na.omit)

t3_11 <- lmer(formula = most.mp.corrupt ~ secondhometot +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige +
              (1|constituency2), 
            data = BESX_t3d, na.action = na.omit)

t3_12 <- lmer(formula = most.mp.corrupt ~ secondhometot + partymatch +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige +
              age + educ + attention + 
              news + telegraph + 
              occup + soctrust + econ12gb  +
              (1|constituency2), 
            data = BESX_t3d, na.action = na.omit)
#-----5 -  Tables: Spillovers: ----
stargazer(t3_1, t3_2, t3_3, 
          t3_4, t3_5, t3_6, 
          t3_7, t3_8, t3_9, 
          t3_10, t3_11, t3_12, type = "text",
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          out = "Table3_SecondHome.html")

```

```{r Appendix F: Spillovers with Other Claims Only} 

#-----1 -  Politicians-----
t3_1 <- lmer(formula = trustplt ~ totexp_excludehome
               + (1|constituency2), 
               data = BESX_t3a, 
               na.action = na.omit)

t3_2 <- lmer(formula = trustplt ~ totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3a, na.action = na.omit)

t3_3 <- lmer(formula = trustplt ~   
                 totexp_excludehome+ partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige +
                 age + educ + attention +
                 news + telegraph + 
                 occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t3a, na.action = na.omit)

#-----2 -  Parliament-----
t3_4 <- lmer(formula = trustprl ~ totexp_excludehome
               + (1|constituency2), 
               data = BESX_t3b, 
               na.action = na.omit)

t3_5 <- lmer(formula = trustprl ~  totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                  female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3b, na.action = na.omit)

t3_6 <- lmer(formula = trustprl ~ totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t3b, na.action = na.omit)
#-----3 -  Satisfaction-----
BESX_t3$satdem = as.numeric(BESX_t3$satdem)

t3_7 <- lmer(formula = satdem ~ totexp_excludehome
               + (1|constituency2), 
               data = BESX_t3c, 
               na.action = na.omit)

t3_8 <- lmer(formula = satdem ~ totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), 
               data = BESX_t3c, na.action = na.omit)

t3_9 <- lmer(formula = satdem ~   
                totexp_excludehome + partymatch +
                incumbentstand.original +
                inner_london + distancelivedfromLondon + 
                female + 
                unemployed + se_managerial + density +
                redistrict_change +
                ukp54margin_notional + prestige +
                age + educ + attention +
                news + telegraph + 
                occup + soctrust + econ12gb +
                 (1|constituency2), 
               data = BESX_t3c, na.action = na.omit)
#-----4 -  Spillover Perceptions-----
BESX_t3$most.mp.corrupt <- as.numeric(BESX_t3$most.mp.corrupt)
t3_10 <- lmer(formula = most.mp.corrupt ~ totexp_excludehome
            + (1|constituency2), 
            data = BESX_t3d, 
            na.action = na.omit)

t3_11 <- lmer(formula = most.mp.corrupt ~ totexp_excludehome +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige +
              (1|constituency2), 
            data = BESX_t3d, na.action = na.omit)

t3_12 <- lmer(formula = most.mp.corrupt ~ totexp_excludehome + partymatch +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige +
              age + educ + attention + 
              news + telegraph + 
              occup + soctrust + econ12gb  +
              (1|constituency2), 
            data = BESX_t3d, na.action = na.omit)
#-----5 -  Tables: Spillovers: ----
stargazer(t3_1, t3_2, t3_3, 
          t3_4, t3_5, t3_6, 
          t3_7, t3_8, t3_9, 
          t3_10, t3_11, t3_12, type = "text",
          star.char = c("*", "**"),
          star.cutoffs = c(0.05, 0.01), 
          out = "Table3_OtherClaims.html")

```

```{r Appendix F: Ordered logits for Table 3}

BESX_t3c$satdem = as.factor(BESX_t3c$satdem)

lm.10b <- clmm(formula = satdem ~ Nexis.s + legg 
               + secondhometot + totexp_excludehome
               + (1|constituency2), 
               data = BESX_t3c, link = "logit", 
               na.action = na.omit)

lm.11b <- clmm(formula = satdem ~  Nexis.s + legg + 
                 secondhometot + totexp_excludehome +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change + 
                 ukp54margin_notional + prestige +
                 (1|constituency2), link = "logit", 
               data = BESX_t3c, na.action = na.omit)

lm.12b <- clmm(formula = satdem ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome + partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige +
                 age + educ + attention +
                 news + telegraph + 
                 occup + soctrust + econ12gb +
                 (1|constituency2), link = "logit", 
               data = BESX_t3c, na.action = na.omit)

BESX_t3d$most.mp.corrupt <- factor(BESX_t3d$most.mp.corrupt, ordered = TRUE)

BESX_t3d = BESX_t3d %>% 
  
  mutate(distancelivedfromLondon = as.numeric(scale(distancelivedfromLondon)), 
         unemployed = as.numeric(scale(unemployed)), 
         se_managerial = as.numeric(scale(se_managerial)), 
         density = as.numeric(scale(density)), 
         redistrict_change = as.numeric(scale(redistrict_change)), 
         ukp54margin_notional = as.numeric(scale(ukp54margin_notional)), 
         prestige = as.numeric(scale(prestige)), 
         age = as.numeric(scale(age)), 
         educ = as.numeric(scale(educ)), 
         attention = as.numeric(scale(attention)), 
         occup = as.numeric(scale(occup)), 
         soctrust = as.numeric(scale(soctrust)))

m4c <- clmm(formula = most.mp.corrupt ~ Nexis.s + legg 
            + secondhometot + totexp_excludehome
            + (1|constituency2), 
            data = BESX_t3d, link = "logit", 
            na.action = na.omit)

m5c <- clmm(formula = most.mp.corrupt ~  Nexis.s + legg + 
              secondhometot + totexp_excludehome +
              incumbentstand.original +
              inner_london + distancelivedfromLondon + 
              female + 
              unemployed + se_managerial + density +
              redistrict_change + 
              ukp54margin_notional + prestige +
              (1|constituency2), link = "logit",
            data = BESX_t3d, na.action = na.omit)

m6c <- clmm2(most.mp.corrupt ~   
                 Nexis.s + legg + 
                 secondhometot + totexp_excludehome + partymatch +
                 incumbentstand.original +
                 inner_london + distancelivedfromLondon + 
                 female + 
                 unemployed + se_managerial + density +
                 redistrict_change +
                 ukp54margin_notional + prestige +
                 age + educ + attention +
                 news + telegraph + 
                 occup + soctrust + econ12gb, 
                 random = factor(constituency2), link = "logistic", Hess = T, 
            data = BESX_t3d, na.action = na.omit)


summary(lm.10b)
summary(lm.11b)
summary(lm.12b)

summary(m4c)
summary(m5c)
summary(m6c)

```
